1. Run a script with no output and in the background
$ ./my_script.sh > /dev/null 2>&1 &
2. Run a script with no output and in the background and see the pid
$ ./my_script.sh > /dev/null 2>&1 & echo $!
3. Template script that loops thru and writes to a file
#!/bin/bash
# $1 - number of minutes
# $2 - task id
COUNTER=$(($1*60/5))
TOTAL=$COUNTER
echo Perfload will run for $1 minutes
echo "Perfload will run for $1 minutes" > /tmp/$2.log
until [ $COUNTER -eq 0 ]; do
echo The counter is $COUNTER
PROGRESS=$(echo "scale=2;($TOTAL - $COUNTER)*100/$TOTAL" | bc -l)
echo "Perfload RUNNING $PROGRESS %" >> /tmp/$2.log
let COUNTER-=1
sleep 5
done
echo "Perfload SUCCESS" >> /tmp/$2.log
7.21.2015
Bash Cheat Sheet
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment