I have a crontab
file located at /usr/bin/crontab
.
It's supposed to run every day at 7:30a est. I don't want to have to wait hours to see if it runs. Aside from changing the time it runs, are there other places I can look to ensure that the script will run at the desired time? I basically want to ensure the crontab file has been loaded in
Thanks!
Edit: When I vi /etc/spool/cron/crontabs
, I see
CGroup: /system.slice/cron.service
" ============================================================================
" Netrw Directory Listing [netrw v156]
" crontabs
" Sorted by name
" Sort sequence: [\/]$,\,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$
" Quick Help: :help -:go up dir D:delete R:rename s:sort-by x:special
" ==============================================================================
../
~
~
Is it possible to check for a file existence in a crontab oneliner, and only execute a script if that file existed?
Pseudocode:
* * * * * run /opt/myscript.sh
asked Jul 28 at 11:51
2
Use an ordinary test for existence, then run the script if the test succeeds.
* * * * * if [ -e /tmp/signal.txt ]; then /opt/myscript.sh; fi
or
* * * * * if test -e /tmp/signal.txt; then /opt/myscript.sh; fi
Or, using the short-circuit syntax. Doing it this way would cause the job to fail if the file does not exist [which may trigger an email from the cron daemon]:
* * * * * [ -e /tmp/signal.txt ] && /opt/myscript.sh
or
* * * * * test -e /tmp/signal.txt && /opt/myscript.sh
You could use the -f
test instead of the -e
test if you want to additionally ensure that /tmp/signal.txt
is a regular file and not a directory, named pipe, or some other type of file.
answered Jul 28 at 11:53
Kusalananda♦Kusalananda
285k32 gold badges566 silver badges859 bronze badges
7
In case you want to adapt full systemd
over cron
, one could use ConditionPathExists=/path/to/file
in the [Unit]
section of the service.
Checking if the path is a file can be a bit more complicated, as the direct test like ConditionIsFile
does not exist.
Option 1 One knows that the file
will never be empty allows for using ConditionFileNotEmpty=/path/to/file
Option 2 If the file may also be of zero size and one needs to check for mere existence and it being a file, one could test for the existence of the path and it not being a directory:
ConditionPathExists=/path/to/file
ConditionPathIsDirectory=!/path/top/file
Where =!
is a logical NOT operator.
answered Jul 28 at 13:48
FelixJNFelixJN
11.5k1 gold badge24 silver badges43 bronze badges
5
Which command displays the PPID?
Ps -f
A user calls with a concern about the display he is seeing after running the command: ps -e. There are a number of processes that display getty and he is afraid that an unauthorized user is attached to the system. How should you respond?
Assure the user that this is normal
Which command displays in the most detail all the processes that are running?
Ps -ef
You want to view all currently-running processes that include getty in the process name. Which command would you use?
Bps -A | grep getty
You answer a call from a number of users who cannot access the mall server. which utility would you use to quickly see if the sendmail service is running?
ps
Which command would you use to look for a potential resource hog on a workstation?
top
You need to see a listing of running processes and system status such as memory and cpu usage. Which command will produce the listing?
Top
Which is the default signal sent to processes by the kill utility?
A developer calls with a problem. They were trying to debug a new daemon and mistakenly placed it on the production machine instead of on a lab machine. It has now entered runaway mode. The PID number is 2345 and attempts have been made to remove it with the standard kill command but it will not stop.
-15
Which command would you use to be assured that the process will terminate?
Kill -9 2345
After a severe lightning strike nearby, a number of processes seem to be running on the server in runaway mode. Which utility terminates these processes by name, and not just by process ID number?
Killall
You have several processes running in the background as shown from the jobs command below: [1] + running gedit & [2]+ stopped crontab e
What command will bring the gedit program to the foreground.
Fg 1
You have a gedit process with a job ID of 6. Which command would you enter at the command prompt to send the process to the background?
bg 6
You need to send a process to the foreground. Which command should you enter to identify the job for the process?
jobs
Which kill option stops and restarts the process with the same Process ID [PID]?
-sighup
What is the result of the nohup gedit & command?
Gedit will start in the background and persist in the background after logging out of the shell.
Which option would you use with the the kill utility at the command prompt to see the valid signals available with this Linux system you’re not familiar with ?
Kill -l
You need to manage a process in the foreground by pressing ctrl+C on this keyboard.what signal code is sent to the process?
SIGINT
Which command would you use to decrease the daemon’s priority?
Renice -n 10 2345
You need to determine the priority of several processes. Which command should you enter to identify the process ID and nice value for each process?
top
What would you enter at the command prompt to start the gedit process with a highest priority possible?
Nice -n -20 gedit
What is the default nice value for a process not executed with the nice command?
0
Which of the following commands starts the gedit program with a priority 1 above the default nice priority?
Nice -n -1 gedit
Which command could you use to verify if a crontab file exists for user thobbs.
Crontab -l -u thobbs
You are editing the crontab file and want an entry to run every hour at five minutes past the hour. Which of the following entries will accomplish this?
5**** /home/emmett/example.sh
You want to keep the gshant user from editing his respective file in /var/spool/cron, but still allow all other users on the system to edit their respective crontab file. What is the full path and filename of the file you should edit?
/etc/cron.deny
Which file should you edit if you want to permit specific users to edit their respective crontab file, but deny all other users on the system from editing their crontab file?
/etc/cron.allow
After logging in as root, you need to manage the crontab files for your Linux system. Which command should you use to edit the crontab file for the gshant user account?
Crontab -ue gshant
Which command should you enter at the command prompt to list the tasks in the at queue for the current user?
At -l
Which daemon must be running if you want to use the at command?
atd
You want to keep the gshant user from running the at command, but still allow all other user to use it. What is the full path and filename of the file you should edit?
/etc/at.deny
Which of the following statements best describes the effects of having only the gshant user account listed on the /etc/at.allow file?
Only gshant and root can use the at command
What should be entered at the command prompt to remove tasks 2 and 3 in the at queue?
Atrm 2,3
If a system is down at the time of a recurring regularly scheduled task is supposed to run, which task scheduling service will run the task when the system is back up again?
anacron
What is the full path and filename of the file that is used to schedule tasks for the anacron daemon?
/etc/anacrontab
You have anacrontab file with the following settings: RANDOM_DELAY=35 START_HOURS_RANGE=17-23 #period in days delay in minutes job-identifier command 1 5 cron.daily nice run-parts /etc/cron.weekly 7 20 cron.weekly nice run-parts /etc/cron.weekly
@monthly 50 cron.monthly nice run-parts /etc/cron.monthly
Between which hours of the day will tasks schedule with anacron start to run?
If the system was down during the time period a weekly task was scheduled to run, what is the minimum amount of time anacron will wait, after the system is back up, before running the task?
If the "delay in minutes" for daily tasks is 5 minutes, how much time will anacron add to the delay of 5 minutes before the scheduled daily task?
Between 5 pm and 11 pm 20 minutes A randomly chosen number of minutes between 0 and 35
What service does cron rely on to run the scripts in the /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly directories?
anacron
Anacron creates a timestamp file that tells you the last time a regularly scheduled job was run. What is the full path and name of the directory that contains these timestamp files?
/var/spool/anacron
You need to install an email server. Which of the following applications are valid Linux email applications?
Sendmail and Postfix
What do you enter at the command prompt to display the contents of an MTA mail queue?
mailq
Which of the following MTAs use the QMQP and QMTP protocols?
qmail
Which of the following MTAs are modular?
Postfix and qmial
By default, which protocol is used by an MTA to send messages to other MTAs?
SMTP
Which of the following are common protocols used by MTAs to send messages to MUAs?
IMAP and POP3
Recently, you updated the /etc/aliases file with several email aliases. What command do you use at the command prompt to update /etc/aliases.db file?
newaliases
Which of the following files stores the aliasing information for MTAs?
/etc/aliases.db
You are logged in as gshant, and you want to forward your mail to the dwant user on the local network. Which file should you edit to redirect the mail for a gshant user?
~/.forward
What is the full path and filename of the file that contains mail for the gshant user?
/var/spool/mail/gshant
Which of the following directories contains email for each user account on the system?
/var/spool/mail
Which database object in an SQL table represents attributes?
columns
Enter the SQL command that will list all tables in the grades database.
SHOW TABLES grades;
Which of the following SQL commands will group information in a list?
GROUP BY
Which SQL database object represents a single entity or item?
RECORD
Which clause should you add to the SELECT command to filter results from an SQL database?
WHERE
You need to show the contents of the location and price fields in the shirt table in an SQL database. Which SQL command should you use?
SELECT location, price FROM shirt
Which clause should you add to the SELECT command to sort results from an SQL database?
ORDER BY
You use the following command to retrieve specific entry information from the shirt table: SELECT location, price FROM shirt. However, the command is not returning any information. What should you do?
Add a semicolon to the end of the statement.
Which of the following statements best describes the purpose of the following SQL command? DELETE FROM shirts WHERE color=’pink’ AND type =’polo’ AND gender=’male’;
Records for men’s pink polo shirts will be removed from the shirts table