LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 10-01-2009, 05:47 AM   #1
glore2002
Member
 
Registered: Mar 2007
Location: Buenos Aires, Argentina.
Distribution: Lubuntu 17.10 x64
Posts: 510

Rep: Reputation: 33
Problem executing scripts from cron.


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?

Thanks,
 
Old 10-01-2009, 05:57 AM   #2
bradvan
Member
 
Registered: Mar 2009
Posts: 367

Rep: Reputation: 61
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?
 
Old 10-01-2009, 06:02 AM   #3
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
The user doesn't has permission to execute shutdown.
Add the crontab as root
Code:
su
crontab -e
Or give the user permissions to shutdown the system.
 
Old 10-01-2009, 06:03 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by glore2002 View Post
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.
 
Old 10-01-2009, 08:00 AM   #5
glore2002
Member
 
Registered: Mar 2007
Location: Buenos Aires, Argentina.
Distribution: Lubuntu 17.10 x64
Posts: 510

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by catkin View Post
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!

Last edited by glore2002; 10-01-2009 at 08:09 AM.
 
Old 10-01-2009, 09:03 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by glore2002 View Post
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?
Code:
10 6 1 oct thu /home/lacalga/bin/tapecorto 12 prueba 00:10:00 >> <my log file name> 2>&1
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.
 
Old 10-01-2009, 10:40 AM   #7
glore2002
Member
 
Registered: Mar 2007
Location: Buenos Aires, Argentina.
Distribution: Lubuntu 17.10 x64
Posts: 510

Original Poster
Rep: Reputation: 33
Quote:
Originally Posted by catkin View Post
Code:
10 6 1 oct thu /home/lacalga/bin/tapecorto 12 prueba 00:10:00 >> <my log file name> 2>&1
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.

Thanks again,
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem executing scripts mierdatuti Linux - General 4 09-19-2008 04:21 AM
Issues while executing shell scripts through Cron job paragkalra Programming 8 08-02-2008 01:18 PM
Executing scripts jonette20 Linux - General 3 10-15-2007 01:50 PM
problem executing user created scripts on console farooqmaniar Linux - Software 1 01-12-2006 06:06 PM
problem executing scripts on mounted fat32 partition roald Linux - General 8 06-14-2004 06:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 11:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration