Chapter 26 Flashcards

Automating Jobs

1
Q

Describe how to run a shell script in background mode from your console or terminal session. 

A

To run a shell script in background mode, include the ampersand sign (&) after the shell script command on the command line. The shell will run the script in background mode and produce another command prompt for you to continue within the shell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain how to disconnect a shell script from the console or terminal session so that it continues running if the session closes. 

A

The nohup command disconnects the shell script from the shell session and runs it as a separate process. If the console or terminal session exits, the shell script will continue running.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain how to stop or pause a shell script running in the foreground on a console or terminal session. 

A

To stop a shell script running in the foreground of a console or terminal session, press the Ctrl+C key combination. To pause a running shell script, press Ctrl+Z.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe how to list shell scripts running in background mode within a console or terminal session. 

A

The jobs command allows you to list the commands that are running within the console or terminal session. The output from the jobs command displays both the job number assigned by the shell and the process ID assigned by the Linux system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe how to run a shell script at a specific time. 

A

The at command allows you to schedule a job to run at a specific time. You can specify the time by using an exact value, such as 10:00 p.m., or by using common date and time references, such as 10:00 a.m. tomorrow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Explain how to run a shell script automatically at a set time every day. 

A

The cron process runs every minute and checks for jobs that are scheduled to run. You must define the jobs to run in the cron table by using the crontab command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Frank wants to run his large number-crunching application in background mode on his console session. What command does he need to use to do that?

>
&
|
>>
nohup
A

B. The ampersand character (&) tells the shell to start the command in background mode from the console session, so option B is correct. The greater-than sign (>) redirects the output from the command to a file, so option A is incorrect. The pipe symbol (|) redirects the output from the command to another command, so option C is incorrect. The double greater-than sign (») appends the output from the command to a file, so option D is incorrect. The nohup command disconnects the session from the console session, so option E is incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What command do you use to disconnect a shell script from the current console so that it can continue to run after the console exits?

>
&
|
>>
nohup
A

E. The nohup command disconnects the shell script from the current console session, so option E is correct. The greater-than sign (>) redirects the output from the command to a file, so option A is incorrect. The ampersand sign (&) runs the shell script in background mode, so option B is incorrect. The pipe symbol (|) redirects the output from the command to another command, so option C is incorrect. The double greater-than symbol (») appends the output from the command to a file, so option D is incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

When Melanie runs a shell script, she notices that it takes up all of the memory on her Linux system and she needs to stop it. How can she do that?

Start it with the nohup command.
Start it with the ampersand (&) command.
Press Ctrl+C while the script is running.
Redirect the output using the pipe symbol.
Use the kill command to stop it.
A

C. The Ctrl+C key combination stops the job currently running in foreground mode on the console session, so option C is correct. Starting a command with the nohup command disconnects the job from the console session, so you can’t stop it from the console with a key command, making option A incorrect. Starting a job with the ampersand (&) command places the job in background mode but doesn’t allow you to stop the job from running, so option B is incorrect. The pipe symbol redirects the output from a shell script to another command, so option D is incorrect. The kill command will stop a running shell script, but if the shell script is running in your console session, you won’t be able to submit the kill command from the command prompt, so option E is incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can you temporarily pause a shell script from running in foreground mode in a console session?

Press the Ctrl+Z key combination.
Press the Ctrl+C key combination.
Start the command with the nohup command.
Start the command with the ampersand (&) command.
Start the command with the fg command.
A

A. The Ctrl+Z key combination pauses the job currently running in foreground mode on the console session, so option A is correct. The Ctrl+C key combination stops the job currently running in the foreground in the console session, rather than pauses it, so option B is incorrect. The nohup command disconnects a job from the console session but doesn’t pause the job, so option C is incorrect. The ampersand sign (&) runs a job in background mode in the console session, so option D is incorrect. The fg command resumes a stopped job in foreground mode, so option E is incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you determine the default job running in a console session?

By the PID number
By the job number
By a plus sign next to the job number in the jobs output
By a minus sign next to the job number in the jobs output
By using the ps command
A

C. When you list the current jobs using the jobs command, there will be a plus sign next to the default job number, so option C is correct. The minus sign next to a job number indicates the job next in line to become the default job, so option D is incorrect. Neither the PID nor the job number indicates the default job, so options A and B are both incorrect. The ps command lists the running jobs but doesn’t indicate the default job in a console session, so option E is incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Barbara has an application running in background mode in her console session and needs to bring it to foreground mode. What command should she use to do that?

bg
fg
nohup
&
at
A

B. The fg command allows you to change a currently running or stopped job to run in foreground mode on the current console session, so option B is correct. The bg command changes a currently running or stopped job to run in background mode, so option A is incorrect. The nohup command disconnects a job from the console session, so option C is incorrect. The ampersand sign (&) places a job in background mode, not foreground mode, so option D is incorrect. The at command runs a job in background mode at a specific time, so option E is incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What command allows you to run a shell script at a specific time?

nohup
&
at
|
>
A

C. The at command allows you to schedule a job to run at a specific time, so option C is correct. The nohup command disconnects a job from the console session, so option A is incorrect. The ampersand sign (&) runs a job in background mode, so option B is incorrect. The pipe symbol (|) and the greater-than symbol redirect the job output to either a command or a file, so options D and E are both incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Nick needs to run a report at midnight every day on his Linux system. How should he do that?

Use the at command to schedule the job.
Run the job using the nohup command.
Run the job using the ampersand (&) symbol.
Schedule the job using cron.
Run the job using the atq command.
A

D. The cron program checks the cron tables for each user account and runs any scheduled jobs automatically, so option D is correct. The at command only runs a specified command once at a scheduled time, so option A is incorrect. The nohup and ampersand (&) commands do not schedule jobs to run, so both options B and C are incorrect. The atq command displays the jobs already scheduled to run from the at command, so option E is incorrect.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When will the cron table entry 10 5 * * * myscript run the specified shell script?

At 10:05 a.m. every day
On May 10th every year
On October 5th every year
At 5:10 p.m. every day
At 5:10 a.m. every day
A

E. The times specified in the cron table are listed in the order of minute, hour, day of month, month, and day of week. The hour is in 24-hour format, so the specified entry would run the job at 5:10 a.m. every day, making option E correct. Options A, B, C, and D are all incorrect times based on the specified entry.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Jane needs to check on what jobs are scheduled to run automatically for her user account. What command should she use to list the cron table entries for her user account?

cron
at
crontab
jobs
nohup
A

C. The crontab command allows you to list or edit the cron table for your own user account, so option C is correct. The cron command is what reads the cron tables for each user account and runs the specified jobs; it doesn’t list the jobs, so option A is incorrect. The at command allows you to schedule a job to run at a specific time, so option B is incorrect. The jobs command allows you to view the currently running or stopped jobs in your console session, so option D is incorrect. The nohup command disconnects the job from the console session, so option E is incorrect.

17
Q
A