LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Schedule a command with 'at' (https://www.linuxquestions.org/questions/linux-newbie-8/schedule-a-command-with-at-819335/)

genogebot 07-12-2010 12:26 AM

Schedule a command with 'at'
 
Hi,

I'm trying to run a command with the 'at' scheduler in Linux Mint 9. It's basically a ssh connection to my Smoothwall firewall to tell it to shut down, but that part isn't really important.

The problem I have is that I can't get the 'at' schedule command to do much. I can type commands into the terminal and they work perfectly. If I enter exactly the same command into 'at' nothing happens.

For example, I can type 'plink -load smoothwall' into a terminal and a new ssh terminal comes up asking for my password to make an ssh connection.

If I create an 'at' job with the same command, ie:
Code:

$ at now + 5 minutes
at> plink -load smoothwall
at> <Ctrl-d>
$

then nothing at all happens when the 5 minutes are up.

I've checked that the job exists by doing an 'atq' command.

Obviously there's something about 'at' that I don't understand. I've googled, I've looked in this forum and I've looked in a copy of 'The Linux Bible 2010' all without success. I've tried various alternative ways of entering the command for a couple of hours and I'm still stuck. Help!

bathory 07-12-2010 12:48 AM

Hi,

Check if atd is running:
Code:

ps -ef|grep atd
Regards

genogebot 07-12-2010 12:59 AM

Thanks for the quick response.

Quote:

Originally Posted by bathory (Post 4030478)
Hi,

Check if atd is running:
Code:

ps -ef|grep atd
Regards

That produces this result:

Code:

daemon    1321    1  0 13:31 ?        00:00:00 atd
root      1626    1  0 13:31 ?        00:00:00 /usr/bin/vmnet-natd -s 6 -m /etc/vmware/vmnet8/nat.mac -c /etc/vmware/vmnet8/nat/nat.conf
phil      5266  5250  0 15:54 pts/0    00:00:00 grep --colour=auto atd

I can get 'at' to work with some things, like I can set up 'at' to shut down my computer with the command 'shutdown -P now' at a later time. The problem is that some commands don't work, and I don't know why.

vigilandy 07-12-2010 01:09 AM

The problem may be that you're attempting commands such as ssh that require password authentication. When "at" commands are executed, there's no terminal associated with the command, so there's no way for the commands to request a password.

From the at man page:

Quote:

For both at and batch, commands are read from standard input or the file specified with the -f option and executed. The working directory, the environment (except for the variables TERM, DISPLAY and _) and the umask are retained from the time of invocation.
If you need to execute ssh commands in your script, I recommend looking into certificate-based authentication.

devendrakoli 07-12-2010 01:19 AM

Hi,

Please check that your command executes from your shell without using at.
If you get success in this, specify the command in a file & use -f , -c , -t paramter with at command.

Regards,
Devendra Koli

genogebot 07-12-2010 01:25 AM

Quote:

Originally Posted by vigilandy (Post 4030494)
The problem may be that you're attempting commands such as ssh that require password authentication. When "at" commands are executed, there's no terminal associated with the command, so there's no way for the commands to request a password.

From the at man page:
If you need to execute ssh commands in your script, I recommend looking into certificate-based authentication.

Ok, I may have given a bad example. Actually, when I do the full ssh transaction using plink (or putty - they're both part of the same package) everything - including the password - is passed as a parameter in the single command. If I do it by typing into a terminal, a ssh terminal briefly flashes up and immediately closes. There is no response required.

So it's:
Code:

plink -load smoothwall -log putty.log -pw <password> -m ~/shutdown.txt
which works perfectly in a terminal without need for any response from me.

Quote:

When "at" commands are executed, there's no terminal associated with the command
I wouldn't be surprised if that was the reason for the problem, but as a rank newbie I don't understand the implications of not having a terminal associated.

genogebot 07-12-2010 01:40 AM

Quote:

Originally Posted by devendrakoli (Post 4030498)
Hi,

Please check that your command executes from your shell without using at.
If you get success in this, specify the command in a file & use -f , -c , -t paramter with at command.

Regards,
Devendra Koli

According to the 'at' manual, the '-c' parameter is only used to output the commands in a job already created, and the -t isn't really necessary - 'at now + n' is a standard form of the command. However, I did try the various combinations of -t and -f and they made no difference. Thanks anyway.

vigilandy 07-12-2010 01:43 AM

OK, I think I misunderstood what command you wanted to do.

So you want to use plink from a windows machine to ssh into a linux box and then use "at" to schedule some task in the future. Is that right?

I'm not too familiar with plink, but assuming the above is true, perhaps you should create a script on the remote machine and use the -f option to run your commands from a file.

so if you have a command file like shutdown.txt, you can tie this file into the at command:
Code:

at now + 5 minutes -f ~/shutdown.txt

genogebot 07-12-2010 01:45 AM

The problem is also because I don't know what sort of commands 'at' can work with. For example, I can type 'gcalctool' in a terminal and up pops the gnome calculator. If I set up 'at' to run the same command, nothing happens.

Why is that? The reason for failure to run gcalctool probably relates to why my other commands don't work.

genogebot 07-12-2010 01:48 AM

Quote:

Originally Posted by vigilandy (Post 4030513)
So you want to use plink from a windows machine to ssh into a linux box and then use "at" to schedule some task in the future. Is that right?

No, I want to use 'at' to run the command that connects with my firewall and tells it, via ssh, to shut down. I can type the command 'plink ...etc' into a terminal and it works. I want 'at' to emulate that at a scheduled time - say in the middle of the night when I'm hopefully asleep. :)

ArfaSmif 07-12-2010 01:58 AM

"gcalctool" needs a display to run so it won't run with "at". You will probably find that you have mail in /var/spool/mail/username which will give you the output from your "at" command. This may give you some extra insight into why your commands are not working via "at".

genogebot 07-12-2010 02:07 AM

Quote:

Originally Posted by ArfaSmif (Post 4030522)
"gcalctool" needs a display to run so it won't run with "at". You will probably find that you have mail in /var/spool/mail/username which will give you the output from your "at" command. This may give you some extra insight into why your commands are not working via "at".

The folder /var/spool/mail/ is empty. I did see in the 'at' man pages that it sends mail, but I didn't know where. Perhaps I haven't configured something necessary to receive mail from the system.

vigilandy 07-12-2010 02:30 AM

I was able to get a simple test to work using plink and at. Here's what I did. I saved the plink command in a local file, plink.txt
Code:

plink user@server -pw <password> 'echo hello > /tmp/1234.txt'
and on my local machine executed the at command:
Code:

$ at now +2 minutes -f plink.txt

genogebot 07-12-2010 02:56 AM

Ok, this is just getting weird!

It's now working - using exactly the same plink command that wasn't working fifteen minutes ago. I've tested it three times in a row, and it's shutting down the firewall exactly on cue.

I've been copying and pasting the command since I started, so I know it's not due to any improvement in my typing ability.

Now I'm really baffled. Do I mark this as 'solved' - or just plain odd?


All times are GMT -5. The time now is 12:06 PM.