scripts

All posts tagged scripts

Forgot where I found this originally, but it’s definitely worth sharing.

 

Save as wikiquery.sh.  chmod 755 wikiquery.sh or /bin/bash wikiquery.sh

./wikiquery.sh linux

“Linux ( or ) is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of Linux is the Linux kernel, an operating system kernel first released 5 October 1991 by” ” Linus Torvalds. http://en.wikipedia.org/wiki/Linux”

init-Script LSB Compliance
The relevant part of LSB spec[27] includes a description of all the return codes listed here.
Assuming some_service is configured correctly and currently not active, the following sequence will help you determine if it is LSB compatible:
Start (stopped):
/etc/init.d/some_service start ; echo “result: $?”
Did the service start?
Did the command print result: 0 (in addition to the regular output)?
Status (running):
/etc/init.d/some_service status ; echo “result: $?”
Did the script accept the command?
Did the script indicate the service was running?
Did the command print result: 0 (in addition to the regular output)?
Start (running):
/etc/init.d/some_service start ; echo “result: $?”
Is the service still running?
Did the command print result: 0 (in addition to the regular output)?
Stop (running):
/etc/init.d/some_service stop ; echo “result: $?”
Was the service stopped?
Did the command print result: 0 (in addition to the regular output)?
Status (stopped):
/etc/init.d/some_service status ; echo “result: $?”
Did the script accept the command?
Did the script indicate the service was not running?
Did the command print result: 3 (in addition to the regular output)?
Stop (stopped):
/etc/init.d/some_service stop ; echo “result: $?”
Is the service still stopped?
Did the command print result: 0 (in addition to the regular output)?
Status (failed):
This step is not readily testable and relies on manual inspection of the script.
The script can use one of the error codes (other than 3) listed in the LSB spec to indicate that it is active but failed. This tells the cluster that before moving the resource to another node, it needs to stop it on the existing one first.

Sure, while running anything faster than one minute probably isn’t needed as it’s probably a bandaid related item that probably should be fixed correctly. But I just ran into a situation today where I said fuck it, I need a bandaid.

Needed a quick solution to basically chmod -R 777 a particular directory used for log shipping. But had to be far faster than every one minute which is the fastest that cron offers with * * * * * . Again this is not the most elegant solution and really don’t recommend chmod -R 777 in most situations, but there are those times..and well this was one of those times… 😉

create new file called bandaid.sh
#!/bin/bash

while [ 1 -eq 1 ]; do chmod -fR 777 /logsfromhell ; sleep 1; done

chmod 755 the bandaid.sh; ./bandaid.sh &

OR add a little insurance to the deal..add this script to cron

#!/bin/bash

CHECKME=ps -ef | grep -v grep |grep '[b]andaid\.sh'
if [ “$CHECKME” ]
then
echo “bandaid hasn’t lost it’s sticky..”
else
/root/scripts/bandaid.sh
fi

chmod 755 checker.sh
* * * * * /root/scripts/checker.sh > /dev/null 2>&1