How do you run a script on login in *nix?

From wikipedia Bash When Bash starts, it executes the commands in a variety of different scripts. When Bash is invoked as an interactive login shell, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads … Read more

Creating temporary files in bash

The mktemp(1) man page explains it fairly well: Traditionally, many shell scripts take the name of the program with the pid as a suffix and use that as a temporary file name. This kind of naming scheme is predictable and the race condition it creates is easy for an attacker to win. A safer, though … Read more

Shell script “for” loop syntax

Brace expansion, {x..y} is performed before other expansions, so you cannot use that for variable length sequences. Instead, use the seq 2 $max method as user mob stated. So, for your example it would be: max=10 for i in `seq 2 $max` do echo “$i” done

Subtract two variables in Bash

Try this Bash syntax instead of trying to use an external program expr: count=$((FIRSTV-SECONDV)) BTW, the correct syntax of using expr is: count=$(expr $FIRSTV – $SECONDV) But keep in mind using expr is going to be slower than the internal Bash syntax I provided above.

Optimal lock file method

Take a look at the enlightening presentation File Locking Tricks and Traps: This short talk presents several common pitfalls of file locking and a few useful tricks for using file locking more effectively. Edit: To address your questions more precisely: Is there a better synchronization method than the lock file? As @Hasturkun already mentioned and … Read more