Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Wednesday, 17 February 2010

bash shell logrotate function

# Yet Another installation in the Yet Another script to do whatever series

# I have done logrotate in bash in at least two other flavours before. :-7

# bash shell logrotate function
function logroti () {
for f in $* ; do
echo logroti for f
if [ -e "$f" ] ; then
ROTFILES=$(find $f.[0-9] 2>/dev/null| sort -r )
for rf in $ROTFILES; do
BASE=${rf%.*}
NUM=${rf##$BASE.}
((NUM++))
echo logroti for rf=$rf BASE=$BASE NUM=$NUM new file $BASE.$NUM
mv -f $rf $BASE.$NUM
done
cp -f $f $f.0
cat /dev/null > $f
fi
done
}

# e.g. usage
logroti run_demo.log
while [ 1 ]; do
logrotate demo.log 2>&1 |tee -a run_demo.log
date |tee -a run_demo.log
echo "DEMO script start" |tee -a run_demo.log
tclsh RunDemo.tcl 2>&1 |tee demo.log
date |tee -a run_demo.log
echo "DEMO script exited" |tee -a run_demo.log
done

# the tcl script internally at top level has a catch {...} sError
# but some errors get past this! :)
# So am catching everything and can see how long things run for and what errors cause any problems

Thursday, 20 August 2009

misleading error syntax error: word unexpected (expecting ")"

This error ("line 1: syntax error: word unexpected (expecting ")")") is misleading.
It leads one initially to suspect a scripting error.
It is because of trying to run an incompatible (maybe elf64) binary on an elf32 platform (x86/i386).

/sbin/udevd: line 1: syntax error: word unexpected (expecting ")")


It is quite like the misleading error you get in solaris 32bit or 64bit "Invalid argument" if trying to run an incompatible binary.

The error on x86_64 is good "cannot execute binary file" leads you to the problem directly.

$ ./hello32sparc
bash: ./hello32sparc: cannot execute binary file
$ ./hello64sparc
bash: ./hello64sparc: cannot execute binary file
$ ./hexdump_arm
bash: ./hexdump_arm: cannot execute binary file
$ uname -s -r -m -p -i -o
Linux 2.6.27.29-170.2.79.fc10.x86_64 x86_64 x86_64 x86_64 GNU/Linux



$ ./hexdump
-bash: ./hexdump: Invalid argument
$ ./hexdump_arm
-bash: ./hexdump_arm: Invalid argument
$ ./hexdump
hexdump hexdump_arm hexdumpx86_32 hexdumpx86_64
$ ./hexdumpx86_32
-bash: ./hexdumpx86_32: Invalid argument
$ ./hexdumpx86_64
-bash: ./hexdumpx86_64: Invalid argument
$ uname -s -r -m -p -i
SunOS 5.10 sun4u sparc SUNW,Sun-Fire-V245


Use objdump to check what platform your binaries are for.

objdump -h hello32sparc
elfdump -e hello32sparc