The trap Command
The trap command can be used to block certain signals or to cause specific commands to be executed when those signals are received.
This can be used to prevent interrupts from halting scripts or to clean up files when a script is interrupted.
trap Signals
- 0 EXIT Exit from shell
- 1 HUP Hangup
- 2 INT Interrupt <ctrl-c>
- 3 QUIT Quit
- 6 ABRT Abort
- 9 KILL Kill
- 14 ALRM Alarm timeout
- 15 TERM Termination signal
trap Examples
- trap “ “ 2
- Ignores Interrupts <ctrl-c>
- trap 2
- trap “rm tmpfile” TERM INT KILL HUP
- Removes tmpfile if halted.
A Bit More on I/O
- &> filename Both standard error and standard out go to filename
- >& 2 Redirect output to standard error
The at Command
- The “at” command can be used to schedule a job to run once at a defined time in the future.
- The scheduled job can be a command, set of commands or script.
- The “at” command defaults to a 24 hour clock, but can handle “am” and “pm”.
- When entering an “at” command, use a <ctrl-d> at the beginning of a line to end the command sequence.
at Command Example
- at 3:00
- at> who >> whoison
- at> date >> whoison
- at> <ctrl-d>
The “at> ” prompt will appear while you are entering the command(s).
at Command Times
- Some versions of the “at” command will accept one or two digits as the hour. (i.e. 11 is interpreted as 11:00 AM).
- All versions of the “at” command will accept three and four digits with a colon. (i.e. 17:15 is interpreted as 5:15 PM)
- “am” and “pm” can be used in place of 24 hour time.
at Command Terminology
The “at” command understands a number of terms including:
- Months: Three characters or full name
- Days: Three characters or full name
- Year: Four digits, sometimes must have a preceding comma(,)
- next week, +3 weeks, +5 months, next year, +4 years, tomorrow
Listing "at" Jobs
You can list your currently scheduled “at” jobs with either of the following commands:
Removing "at" Jobs
Assuming that you have an at job called “7”, you can remove it using either of the following commands: