Running script file using cron job every 5 second

Hi All,

I beginner in unix, i have no idea how to set the script file using cron job every 5 second. I also want to execute automatically the output to text file.This is my script name countsys.sh and my textfile abc.txt.

Minimum configuration in cron is minutes, you cannot set it for 5 seconds.

May be, invoke a script every minute, and then make that to execute the command for every 5 seconds for that one minute.

Did you mean,

countsys.sh >> abc.txt

In your script, you can use repeating loop and after ending the business logic use sleep 5.

After sleeping for 5 seconds, the script logic will be executed again. :slight_smile:

Hope it works for you !! The script will look somewhat like this..

while ( )
{
<business logic>
sleep 5
}

after this you can make this entry in cronjob and set it to execute on a particular time..

give a try ..

Hi all,

I means that i want run my script automatically and the text file have been create also already update after the script finish to execute. So i dont type the script name example countsys.sh in command line.So the script automatically run and show the output in text file..I dont have any idea for do this, If you all have idea how to do please let me know....

U can run ur script as below.
Open your crontab file and add the below lines to the file and save it.
It will do the required.

* * * * * /path where countsys.sh script exists/ >> /path for abc.txt
* * * * * /bin/sleep 5; /path where countsys.sh script exists/ 

Hope this works.

hi nessj,

i have try it, but the text.file can't see when i use cat command.
Do you know what it means

countsys.sh[40]: abc.txt: Execute permission denied

hope you can give the answer...

This will not work.
Moreover, there is no need to make use of cron here.

You can prepare a script which will run in an infinite loop, with a sleep of 5 seconds and run the script in the nohup.