shell | script self run check

LINUX: MYARGS=”$(ps -wwo args= $$)”; ps wwaux | grep -v grep | grep “$MYARGS” | grep -vwe “$$” -vwe “$PPID” && exit LINUX && OPENBSD: MYARGS=”$(ps -wwo args= -p $$)”; MYSESS=”$(ps -wwo sess= -p $$)”; ps -wwo sess,args= | grep -v grep | grep “$MYARGS” | grep -vw $MYSESS > /dev/null 2>&1 && exit

SQLITE | BASH | handle ‘database locked’

function do_sql { DB=”$1″ shift test -r “$DBDIR/$DB” if [ $? -ne 0 ]; then write2log “Creating DB $DB” create_db “$DB” fi if [ “x$@” == “x” ]; then return 1; fi LOOP=1;MAXLOOP=10 while true;do $SQLITE “$DBDIR/$DB” “$@” 2>/dev/null && return 0 LOOP=$(( $LOOP + 1 )) RD=”0.$(( ( RANDOM % 9 ) + 1 […]

writing to a pipe by a script started via cron

You run into trouble? Your script started by cron and stdout to a pipe behaves strange? (Pipe made by ‘mknod /var/pipes/mypipe p’.) [ * * * * * myscript.sh > /var/pipes/mypipe ] Solution: You have to read from this pipe, by a process or by hand. [tail -f /var/pipes/mypipe]

shell | scripting ping

Theres a little problem using ping as a connection checker inside of scripts. In example: If you send a bulk of three pings and one of them fail, the ping coommand returns 1. Here is a workaround: function ping_wrapper() { C_IP=”$1″ C_CNT=”$2″ C_TIMEOUT=”$3″ CNT=0 while true; do ping -q -c 1 -w $C_TIMEOUT $C_IP > […]