Shell script timed background execution

Source: Internet
Author: User

1. Use the & symbol to execute commands in the background

You can add the & symbol to the Linux command or script to make the command or script execute in the background, for example:.

$./my-shell-script.sh &

2. Use Nohup to execute commands in the background

After you use the & symbol to execute commands or scripts in the background, the command is automatically terminated if you log out. To avoid this situation, you can use the Nohup command as follows:

$ nohup./my-shell-script.sh &

3. Use screen to execute commands

After the command is executed in the background through the Nohup and & symbols, the command will be executed even if you log out. However, you cannot reconnect to this session and you can use the screen command to reconnect to this session.

The Linux Screen command provides the ability to detach and reconnect a session. When you reconnect to this session, your terminal is exactly the same as when you were separated.

4. Use at to execute a command as a batch

With the AT command, you can have a command run at a specified date and time, for example, to execute the backup script in the background at 10 o'clock in the morning tomorrow, and execute the following command:

$ at-f backup.sh tomorrow

Some of the tasks that you perform in batch mode require some options to be enabled. The following article will give a detailed explanation:.

    • How-to-Capture Unix Top Command Output to a File in readable Format
    • Unix BC Command Line Calculator in Batch Mode
    • How-to-Execute SSH and SCP in Batch Mode (if passwordless login is enabled)
5. Use watch to execute a command continuously

To run a command at a constant interval, you can use the Watch command as follows:

$ watch Df-h

Shell script timed background execution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.