LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-19-2019, 12:48 PM   #1
apaquet
LQ Newbie
 
Registered: Dec 2019
Posts: 2

Rep: Reputation: Disabled
at verses cron syntax


I am running scripts via cron without issue but I have a need to run something similar with at. I am sending 2 arguments, XYZ and 1, to my script. My working cron line is
Code:
*/2 0,1,3-23 * * 0-6 /usr/bin/sh /home/user/dir/script.sh XYZ 1 >/dev/null 2>&1
The script writes an output file in /home/user/dir/ and the script uses full, not relative, path definitions. I have tried a dozen different variations of my working cron line, as the user and as root, with no success and I've also searched high and low but I am finding it very hard to find any relevant information using "at" in searches...go figure.

Please save my sanity!
 
Old 12-19-2019, 01:05 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,764

Rep: Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931Reputation: 5931
It should not be hard to find at command howtos.

Code:
echo "sh /home/user/dir/script.sh XYZ 1 >/dev/null 2>&1" | at <execution time>
https://tecadmin.net/one-time-task-s...mmad-in-linux/
 
1 members found this post helpful.
Old 12-19-2019, 01:12 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,738

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
What, exactly, have you tried? Show us the at command lines you entered and tell us what did (or didn't) happen.
"no success" doesn't give us much to go on to help.
 
Old 12-19-2019, 01:38 PM   #4
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by apaquet View Post
I am running scripts via cron without issue but I have a need to run something similar with at.
Cron syntax (periodical) and at syntax (one time execution) have got nothing to do with each other, in most distributions they're even completely different daemons.

Code:
*/2 0,1,3-23 * * 0-6 /usr/bin/sh /home/user/dir/script.sh XYZ 1 >/dev/null 2>&1
Just for info: as "0" is the same as "7" (sunday), the 0-6 in the 5th field means everyday in the week, so the "*" value would do the same.
 
Old 12-19-2019, 01:57 PM   #5
apaquet
LQ Newbie
 
Registered: Dec 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
Red face Thanks...PEBKAC

I was trying things doing "at now + 1 minute" and then entering commands, ENTER, then ctrl-d. However, after getting the echo "CMD" | at <execution time> syntax and it still was not working, I realized I had logged in as root and su to user but I was still in the /root directory...After opening a new session as user the recommended notation worked.

PEBKAC - Problem Exists Between Keyboard and Chair. I will hang my head in shame for 1 hour.
 
Old 12-19-2019, 04:50 PM   #6
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by apaquet View Post
PEBKAC - Problem Exists Between Keyboard and Chair.
Other variant: PEBKAB (with Brain as the last word).
 
Old 12-19-2019, 06:44 PM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,738

Rep: Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222Reputation: 2222
Quote:
Originally Posted by apaquet View Post
I was trying things doing "at now + 1 minute" and then entering commands, ENTER, then ctrl-d. However, after getting the echo "CMD" | at <execution time> syntax and it still was not working, I realized I had logged in as root and su to user but I was still in the /root directory...After opening a new session as user the recommended notation worked.

PEBKAC - Problem Exists Between Keyboard and Chair. I will hang my head in shame for 1 hour.
I've also heard ALNATKB -- A Loose Nut At The Keyboard.

I have developed the habit of using
Code:
su - user
when switching from root to a user. The minus (-) causes the the login to switch to the user's environment and home directory, which is what one wants most of the time in that situation.
 
1 members found this post helpful.
Old 12-20-2019, 02:47 AM   #8
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by scasey View Post
I have developed the habit of using
Code:
su - user
when switching from root to a user.
I've even aliased (system-wide) su to su -, you normally always want to switch to the new user's home dir (and aliases, etc). So both going towards root as from root to another user ID.
 
1 members found this post helpful.
  


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
am/pm verses 24 hour time CouchMaster SUSE / openSUSE 8 05-20-2015 10:13 AM
ISC Bind 9.2.4 verses 9.3.3 gparker Red Hat 1 01-25-2007 07:29 PM
Compiling C code Under Linuix verses Unix jonesth Programming 2 09-12-2005 08:02 AM
free downloads verses buying startingnow Linux - Distributions 2 08-30-2004 02:47 PM
PHP verses CGI Perl te_conway Linux - Security 2 03-28-2002 07:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:54 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