The world of Linux is filled with so much fun and interesting stuffs, the more we go in, the more we find stuffs. In our efforts to bring those little hacks and tips for you that makes you different from others, here we have came up with three little tricks.
1. How to Schedule a Linux Job Without Cron
Scheduling a job/command in Linux is acronym to cron. Whenever we need to schedule a job, we call cron, but do you know we can schedule a job at a later time without corn? You can do it as suggested below..
Run a command (say date) every 5 sec and write the output to a file (say date.txt). To achieve this scenario, we need to run the below one liner script directly on the command prompt.
Anatomy of the above one liner script:
- while true – Ask script to run while the condition is true, it acts as a loop which makes the command to run again-and-again or say in a loop.
- do – do perform what follows, ie., execute command or set of commands that lies ahead of do statement.
- date >> date.txt – here the output of date command is being written to a file date.txt. Also note that we have used >> and not >.
- >> ensures that the file (date.txt) is not overwritten every time the script execute. It just append the changes. Whereas > overwrite the file again and again.
- sleep 5 – It ask the shell to keep a time difference of 5 seconds before it executed again. Note the time here is always measured in seconds. Say if you want to execute the command every 6 minutes, you should use (6*60) 360, in succession of sleep.
- done – marks the end of while loop.
- & – Put the whole process in loop to background.
No comments:
Post a Comment