Is it possible in Linux command line to have a command repeat every n seconds?
Say, I have an import running, and I am doing
ls -l
>
Running commands periodically without cron is possible when we go with while.
As a command:
while true ; do command ; sleep 100 ; done &
[ ex: # while true; do echo `date` ; sleep 2 ; done & ]
Example:
while true
do echo "Hello World"
sleep 100
done &
Do not forget the last & as it will put your loop in the background. But you need to find the process id with command "ps -ef | grep your_script" then you need to kill it. So kindly add the '&' when you running the script.
# ./while_check.sh &
Here is the same loop as a script. Create file "while_check.sh" and put this in it:
#!/bin/bash
while true; do
echo "Hello World" # Substitute this line for whatever command you want.
sleep 100
done
Then run it by typing bash ./while_check.sh &