Archive for the script Category

Setting time without ntp access

Testing some hardware at a lab I ran into a time sync issue. The servers  didn't have outbound access to ntp (port 123 tcp or udp) but the servers had full outbound access to the web (port 80 and 443 tcp). Only having access to the servers for a week I didn't want to waste much time on setting up time. This is the hack I came up with. I created a script called set_time.sh and added it to roots cron so it would run every 15min. This kept time in sync enough for my testing. #!/bin/bash date Read more [...]

Vacuum Firefox, Thunderbird and Eclipse Squlite script

Wrote this little bash script after I learned about squlite vacuum. #!/bin/bash #Best to stop the apps before but just incase if [ $(pgrep thunderbird >> /dev/null 2>&1)$? = "0" ]; then echo "please stop thunderbird" sleep 10 pkill thunderbird fi if [ $(pgrep firefox >> /dev/null 2>&1)$? = "0" ]; then echo "please stop firefox" sleep 10 pkill firefox fi if [ $(pgrep eclipse >> /dev/null 2>&1)$? = "0" ]; then echo "please stop Read more [...]

Sudosh and Rootsh

The reason for sudosh and rootsh is to log all commands ran in the root shell. This keeps the security people off your back and makes security audits go smother. You need to do some sudoers tweaking to make sure root is only used with the rootsh or sudosh wraper. Rootsh is in most the repos and is a more active project but I found sudosh has a better play back.  Rootsh also logs to syslog which I don't think sudosh2 does. Logging to syslog gives you the ability to log remotely which Read more [...]

Firefox and Thunderbird backup script

Simple script I run from cron to backup Firefox and Thunderbird. replace YOURHOMEDIR with your actual home directory or make it a variable. #!/bin/bash TODAY=$(date +%F) YESTERDAY=$(date -d "-1 day" +%F) THUNDDIR="/home/YOURHOMEDIR/.mozilla-thunderbird" THUNTAR="/home/YOURHOMEDIR/.mozilla-thunderbird-$TODAY.tar.gz" OLDTHUNTAR="/home/YOURHOMEDIR/.mozilla-thunderbird-$YESTERDAY.tar.gz" FOXDIR="/home/YOURHOMEDIR/.mozilla" FOXTAR="/home/YOURHOMEDIR/.mozilla-$TODAY.tar.gz" OLDFOXTAR="/home/YOURHOMEDIR/.mozilla-$YESTERDAY.tar.gz" #back Read more [...]

CPU Scaling script

I'm posting this thinking someone might find it useful. At one time I was calling this from cron, setting CPU scaling to performance from 8-5 and setting it to on demand all other times.  I got smarter and now let the kernel take care of itself. #!/bin/bash function morepower { for X in $(grep processor /proc/cpuinfo |awk '{print $3}'); do echo "Processor $X Current: $(cat /sys/devices/system/cpu/cpu$X/cpufreq/scaling_governor)" ; done if [ "$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)" Read more [...]

Update hostblock script

I use this script to update my second host file. See post Second Host file to block internet garbage for more information on this and how to put this script to use. #!/bin/bash if [ $(id -u) != "0" ]; then echo "Must be root to run $0" exit 1 fi HOSTFILE="/etc/hostsblock" OLDDATE=$(grep Updated $HOSTFILE |awk '{print $4}') wget --progress=dot -O $HOSTFILE http://www.mvps.org/winhelp2002/hosts.txt NEWDATE=$(grep Updated $HOSTFILE |awk '{print $4}') dos2unix $HOSTFILE if Read more [...]

Rename to all lower script

This script will rename the file name you pass it to all lower case using tr #!/bin/bash # This script renames a file to lowercaseif [ "$1" = "" ]; then echo "Must pass filename." exit fiLOWERNAME="$(echo "$1" | tr '[A-Z]' '[a-z]')"if [ $1 != $LOWERNAME ]; then mv "$1" "$LOWERNAME" ls -Al $LOWERNAME fiYou can run it on multiple files in a directory with something likefor X in $(ls -1); do ./rename_lower.sh $X; done Read more [...]

Pngcrush Script

I wrote this little bash script to pngcruns images in a directory. It will create one thread per processor. #!/bin/bash #multithreaded pngcrushusage () { echo "Usage: sudo $0 /dir" exit 1 }hash_progress () { while [ -d /proc/$! ]; do echo -n "#"; sleep 1; done; echo -ne "\n" }# Check permissions for ownership fix after crush. Run with sudo. if [ `id -un` != root ]; then usage fi# Few sanity checks. [ ! `which pngcrush` ] && echo "pngcrush missing" && Read more [...]