Ask Your Question
0

i want to run a command every hour - how i can do this without using cron-tab?

asked 2014-10-04 10:37:47 -0600

Tiger gravatar image

updated 2014-10-06 07:57:01 -0600

FranciscoD_ gravatar image

i am want to remove all the file and folder in a specific folder after every 1 hour any method. please suggest me. thank you in advance

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2014-10-07 16:03:11 -0600

dionstarfire gravatar image

updated 2014-10-07 16:12:03 -0600

I have a folder that I want cleared every hour when I am logged in. I added a .desltop file that points to my shell script shell in the /home/user/.config/autorun Note: Replace username with the actual user's userID
You can also modify the path to your scipt as you desire.

--- example of desktop file ---
[Desktop Entry]
Comment[en_US]=
Comment=
Encoding=UTF-8
Exec=/home/**username**/bin/setx
GenericName[en_US]=
GenericName=
Hidden=false
Icon=computer-laptop
MimeType=
Name[en_US]=Set X video
Name=Set X video
Path=/home/**username**/bin
StartupNotify=false
Terminal=false
TerminalOptions=
Type=Application
Version=1.0
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-KDE-SubstituteUID=false
X-KDE-Username=

--- end of desktop file ---

in my script I do whatever is necessary but first I lock it in a loop when the script hits the sleep command it will sleep for N seconds example: sleep 60 Will sleep for 1 minute. (please not that the code below is pseudo and not tested)

while [ true ]; do
   dosomething
   sleep [number of seconds to sleep for]
done
edit flag offensive delete link more
1

answered 2014-10-04 12:40:20 -0600

If you don't want to use cron for some reason, you can also do scheduled tasks with systemd timer units.

man systemd.timer explains how. There are some existing .timer files in /usr/lib/systemd/system/ you can use as a guide.

edit flag offensive delete link more

Comments

Another solution could be man at. One can also do this using other programming languages - python, C etc. Write yourself a program. It really depends on what you want to do. Another question is - why not cron? It's exactly what cron does - run commands periodically.

FranciscoD_ gravatar imageFranciscoD_ ( 2014-10-06 07:58:25 -0600 )edit
0

answered 2014-10-05 04:38:55 -0600

mclmmc gravatar image

with crontab installed, you may put your command into a file under "/etc/cron.hourly"

for normal user, create e crontab file (crontab -u user -e); see man page [crontab(5)] for the meaning of each fields, if you read carefully, at the end you will find the answer to your question.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-10-04 10:37:47 -0600

Seen: 1,000 times

Last updated: Oct 07 '14