LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   at verses cron syntax (https://www.linuxquestions.org/questions/linux-server-73/at-verses-cron-syntax-4175666244/)

apaquet 12-19-2019 12:48 PM

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!

michaelk 12-19-2019 01:05 PM

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/

scasey 12-19-2019 01:12 PM

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.

ehartman 12-19-2019 01:38 PM

Quote:

Originally Posted by apaquet (Post 6069542)
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.

apaquet 12-19-2019 01:57 PM

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.

ehartman 12-19-2019 04:50 PM

Quote:

Originally Posted by apaquet (Post 6069559)
PEBKAC - Problem Exists Between Keyboard and Chair.

Other variant: PEBKAB (with Brain as the last word).

scasey 12-19-2019 06:44 PM

Quote:

Originally Posted by apaquet (Post 6069559)
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.

ehartman 12-20-2019 02:47 AM

Quote:

Originally Posted by scasey (Post 6069616)
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.


All times are GMT -5. The time now is 02:33 AM.