Linux - NewbieThis 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
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.
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:
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!
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.
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.
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.
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:
Quote:
Originally Posted by vigilandy
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.
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.
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:
Quote:
Originally Posted by devendrakoli
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.
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:
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:
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.
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:
Quote:
Originally Posted by vigilandy
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.
"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".
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:
Quote:
Originally Posted by ArfaSmif
"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.
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:
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.