DebianThis forum is for the discussion of Debian Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am adding the following scripts to cron via crontab -e (as user)
Quote:
# m h dom mon dow command
10 6 1 oct thu /home/lacalga/bin/tapecorto 12 prueba 00:10:00 >> dev/null 2>&1
25 6 1 oct thu sudo /sbin/shutdown -h now >> /dev/null 2>&1
The first one is to record tv. I've added dev/null 2>&1 at the end. No too clear why but without it, it records only a few seconds.
The second script is (as you should already noticed) to turn off my computer at 6:25 am. It doesn't work (with or without dev/null 2>&1). I am surely forgetting something important. Could you please tell me what is it?
The crontab has it's own path setup. It may not know where to find sudo. It's always best to put the full path in for all objects. As for your first entry, I'm not familiar with the application. Does it work from the command line?
The first one is to record tv. I've added dev/null 2>&1 at the end. No too clear why but without it, it records only a few seconds.
The second script is (as you should already noticed) to turn off my computer at 6:25 am. It doesn't work (with or without dev/null 2>&1). I am surely forgetting something important. Could you please tell me what is it?
The first needs >> dev/null 2>&1 because it is producing some output to terminal which cron has no place to send (because there is no terminal for the job) so it stops running the executable (script?). By redirecting all output to "nowhere" you ensure there is no output to terminal and cron does not stop the job. You may prefer to send output to a log file instead of /dev/null, in case there are some error messages you want to see to solve a problem.
When you run the other command at a terminal, do you have to enter a password? If not, then try changing sudo to /usr/bin/sudo.
The first needs >> dev/null 2>&1 because it is producing some output to terminal which cron has no place to send (because there is no terminal for the job) so it stops running the executable (script?). By redirecting all output to "nowhere" you ensure there is no output to terminal and cron does not stop the job. You may prefer to send output to a log file instead of /dev/null, in case there are some error messages you want to see to solve a problem.
When you run the other command at a terminal, do you have to enter a password? If not, then try changing sudo to /usr/bin/sudo.
What if I want to send (as you said) the output to a log file? How should I do that? What should I add instead of /dev/null?
Regarding to sudo, I will try writing full path instead of just sudo. By the way How do I assign root right to lacalga user?
Thanks to all of you for the help provided. I appreciate it!
where <my log file name> is whatever you want, perhaps /home/prueba/tapecorto.log
Dunno about sudo. Never knowingly use it. Plenty of stuff out there to netsearch for or you could try reading the sudo (and sudoers?) man page. Why don't you just run the command root's crontab? Then you wouldn't need sudo.
Generally squeaking you dinna wanna have root privileges except when you want them (IYSWIM) because you (or malfeasing programs that have sneaked into running with your privileges) can do a lot of harm that way.
where <my log file name> is whatever you want, perhaps /home/prueba/tapecorto.log
Dunno about sudo. Never knowingly use it. Plenty of stuff out there to netsearch for or you could try reading the sudo (and sudoers?) man page. Why don't you just run the command root's crontab? Then you wouldn't need sudo.
Generally squeaking you dinna wanna have root privileges except when you want them (IYSWIM) because you (or malfeasing programs that have sneaked into running with your privileges) can do a lot of harm that way.
Very clear again. I share your opinion about root privileges. I will create the task as root.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.