JPHHLASH

some useful shell scripts
Home
header files
Linux Commands
access windows partition from linux
startup
compiling from source code
how to run C/C++ programs in linux
some useful shell scripts
environment variables
fork and exec
Using apache
php in linux
read/write in linux

To run a shell script first save the script in a file say shhscript then run the script using the sh command.
example
sh shhscript

Common mistakes made during shell scripting


* while using expr or for assigning piped commands to a variable ,use the back quote `(over the tab key) and not the single quote ' near the enter key.


* There should be spaces inside the third brackets in decision/loop commands eg
while [ $i -le 150 ]
if [ $min -ge 50 ]


* To kill a program you made(in case it entered into an infinite loop),find the program in ps -ax list with the name sh and kill it.


break.gif

Using cron to stop an internet connection using pppoe dialer at 02:00 am
$at 02:00 am
at>pppoe-start
at>ctrl d
job 15 at 2007-06-03 02:00

Using cron to print "hmmmmmm" on screen at 01:03 am
at 01:03 am
at> clear > /dev/pts/4
at> echo "hmmmm" > /dev/pts/4
at>
job 15 at 2007-06-03 01:03
$ hmmmm



Using at to read commands from a file
$cat >cmdfile
clear > /dev/pts/4
echo "hmmmm" > /dev/pts/4
ctrl D

$at 01:27 < cmdfile
job 16 at 2007-06-03 01:27
$ hmmmm



To beep irritatingly usisng loop
i=0
while [ $i -le 150 ]
do
beep
i=`expr $i + 1`
done



To list the filenames instead of exiting ,when interrupted ie when pressed ctrl+c
trap 'ls' EXIT
i=0
while [ $i -le 10 ]
do
echo "meow"
done



.

Feedback, query, ideas? Email crenshaw_jo@yahoo.com.