Linux Scripts

Record server uptime in text file

Create a shell script and execute that shell script. TODAY=$(date +"%T") SCRIPT=$(uptime | awk '{print $(NF-2)" "$(NF-1)" "$(NF-0)}') echo "$TODAY | $SCRIPT" >> /root/script/out.txt  

Read more...

How to run time consuming commands on server and also do benchmarking

Make a shell script file. nano script_benchmakring.sh #!/bin/bash echo `date` > /home/log.txt sleep 5 echo `date` >> /home/log.txt You can place any command in the script in place of "sleep 5". We are using sleep command to verify everything is working fine and time difference is being recorded. Now we will make this script executable chmod +x...

Read more...

How to write your first shell script

Launch a terminal vi, nano or any other prefered editor of your choice. I will be using nano as a editor. nano /home/bash-scripts/my-first-script.sh At the top type the following code #!/bin/bash. This is known as a Shebang line. #!/bin/bash echo "start of script" ls echo "end of script" This script prints a header line then list...

Read more...