Scripts

From kipiki
Jump to: navigation, search

Summary

These scripts may be useful to you, check em out, maybe search the page for something you're looking for.

Scripts

Drive maintenance

Destructive r/w test of all specific sized drives on a system, good for doing mass check of drives before raiding them

# This script pulls the 1.8TB drives on my system, and does a badblocks destructive check (this erases all data on these drives, be sure you are doing the correct ones) and dumps output to the out files along with being able to go into them with screen to watch the progress.

for i in `fdisk -l | grep "1.8 TiB" | awk '{print $2}' | awk -F: '{print $1}'`; do screen -dmS "`echo $i|awk -F/ '{print $NF}'`" bash -c "/sbin/badblocks -wsv -o `echo $i|awk -F/ '{print $NF}'`.out $i"; done

# This is a quick and dirty way of checking all of the screen sessions to see their status, use <ctrl>+a then d to get out of each and it will start the next

for i in `screen -ls | awk '{print $1}'`; do screen -r $i; done

handbrake

Here I wanted to find any video that was bigger then 1920x1080 and shrink it down to 1920x1080 to save space using handbrake


screen

Here is an example screen session that starts using cron, runs a minecraft server, and restarts the minecraft server every night with warnings to keep the JVM fresh.

## This script starts the minecraft server, names the screen session minecraft
cat mc.sh
#!/bin/bash
screen -dmS minecraft bash -c 'cd /base/directory/minecraft; jre1.8.0_151/bin/java -Xmx4G -Xms4G -jar minecraft_server.jar'

## This script restarts it after letting the users know, since it knows the screen name it is able to push commands directly into it
cat cycle_mc.sh
#!/bin/bash
screen -S minecraft -X stuff "say Restarting server in 5 min $(echo -ne '\r')"
sleep 60
screen -S minecraft -X stuff "say Restarting server in 4 min $(echo -ne '\r')"
sleep 60
screen -S minecraft -X stuff "say Restarting server in 3 min $(echo -ne '\r')"
sleep 60
screen -S minecraft -X stuff "say Restarting server in 2 min $(echo -ne '\r')"
sleep 60
screen -S minecraft -X stuff "say Restarting server in 1 min $(echo -ne '\r')"
sleep 50
screen -S minecraft -X stuff "say Restarting server in 10 seconds $(echo -ne '\r')"
sleep 5
screen -S minecraft -X stuff "say Restarting server in 10 seconds $(echo -ne '\r')"
sleep 1
screen -S minecraft -X stuff "say Restarting server in 5 seconds $(echo -ne '\r')"
sleep 1
screen -S minecraft -X stuff "say Restarting server in 4 seconds $(echo -ne '\r')"
sleep 1
screen -S minecraft -X stuff "say Restarting server in 3 seconds $(echo -ne '\r')"
sleep 1
screen -S minecraft -X stuff "say Restarting server in 2 seconds $(echo -ne '\r')"
sleep 1
screen -S minecraft -X stuff "say Restarting server in 1 seconds $(echo -ne '\r')"
sleep 1
screen -S minecraft -X stuff "stop $(echo -ne '\r')"
sleep 30
screen -dmS minecraft bash -c 'cd /base/directory/minecraft; java -Xmx4G -Xms4G -jar minecraft_server.jar'