LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2010, 12:26 AM   #1
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Rep: Reputation: 20
Unhappy 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!
 
Old 07-12-2010, 12:48 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

Check if atd is running:
Code:
ps -ef|grep atd
Regards
 
Old 07-12-2010, 12:59 AM   #3
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 20
Thanks for the quick response.

Quote:
Originally Posted by bathory View Post
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.
 
Old 07-12-2010, 01:09 AM   #4
vigilandy
Member
 
Registered: Mar 2010
Location: Tokyo
Distribution: Arch, Fedora
Posts: 71

Rep: Reputation: 23
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.
 
Old 07-12-2010, 01:19 AM   #5
devendrakoli
LQ Newbie
 
Registered: Jun 2008
Posts: 5

Rep: Reputation: 0
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
 
Old 07-12-2010, 01:25 AM   #6
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by vigilandy View Post
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.
 
Old 07-12-2010, 01:40 AM   #7
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by devendrakoli View Post
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.
 
Old 07-12-2010, 01:43 AM   #8
vigilandy
Member
 
Registered: Mar 2010
Location: Tokyo
Distribution: Arch, Fedora
Posts: 71

Rep: Reputation: 23
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
 
Old 07-12-2010, 01:45 AM   #9
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 20
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.
 
Old 07-12-2010, 01:48 AM   #10
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by vigilandy View Post
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.
 
Old 07-12-2010, 01:58 AM   #11
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
"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".
 
Old 07-12-2010, 02:07 AM   #12
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by ArfaSmif View Post
"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.
 
Old 07-12-2010, 02:30 AM   #13
vigilandy
Member
 
Registered: Mar 2010
Location: Tokyo
Distribution: Arch, Fedora
Posts: 71

Rep: Reputation: 23
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
 
Old 07-12-2010, 02:56 AM   #14
genogebot
Member
 
Registered: Jun 2010
Location: Brisbane, Australia
Distribution: Xubuntu 16.04.1 / Linux Mint 18 XFCE / Linux Mint 18 Mate / Ubuntu Server 16.04.1 / Lubuntu 16.04.1
Posts: 146

Original Poster
Rep: Reputation: 20
Question

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?
 
  


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
Using 'AT' and 'CRONTAB' to Schedule Without User Input Jesdisciple Programming 20 03-22-2008 08:53 PM
using 'at' and 'batch' command harry_0098 Linux - Newbie 1 10-30-2007 10:07 AM
'at' command does not work anymore gregorian Linux - Newbie 2 03-17-2007 11:05 AM
Returning from the 'at' command prompt? SlowCoder Linux - Newbie 9 03-08-2007 04:19 PM
'at' command not working minike Slackware 9 03-04-2006 07:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:45 AM.

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