Tag Archives: Linux Shell

Several methods of executing multiple commands in Linux shell

can execute more than one command at a time on the command line, in the following categories:

1. Use between each command;

indicates that the execution results of each command will not affect the execution of other commands. In other words, each command will execute,
but there is no guarantee that each command will execute successfully.

cd /home/PyTest/src; python suning.py

2. Use &amp between each command; & Separate
indicates that the following command will only be executed if the previous command succeeds. This ensures that all commands are executed successfully.

cd /home/PyTest/src&&python suning.py

3. Use | or | or | between each command
.

pipe can direct the output of one command to the input of another, allowing two (or more) commands to work in a continuous pipeline, constantly processing text streams. On the command line, we use | for pipes

cd /home/PyTest/123 || echo "error234"
cd /home/PyTest/123 | echo "error234"

Delete the specified crontab timer task under Linux

1. Create two new script files to test

test1.sh

ping 114.114.114.114

test2.sh

ping 8.8.8.8 

2. Edit crontab task by crontab -e command, and add the following contents:

*/1 * * * * /dd/shell/test1.sh
*/1 * * * * /dd/shell/test2.sh

After adding

, check the crontab content:

[root@localhost shell]# crontab -l
*/1 * * * * /dd/shell/test1.sh
*/1 * * * * /dd/shell/test2.sh

added crontab task, in /var/spool/cron directory will have a file named the current login account. Let’s say My login is root. A root file exists. The contents of this file are the crontab tasks that you just added.

[root @ localhost cron] # cat/var/spool/cron/root/1
* * * * */dd/shell/test1. Sh
* * * * */1/dd/shell/test2. Sh

3. Delete test2.sh from crontab

is where sed is used to process the /var/spool/cron/root file and delete the line containing test2.sh.

 sed -i '/test2.sh/d' /var/spool/cron/root 

Crontab -l command after the
command.

[root@localhost shell]# crontab -l
*/1 * * * * /dd/shell/test1.sh

you can see that the task for test2.sh has been removed. Through observation, the steps of test2.sh are no longer performed. Indicates that the deletion was successful.

4. Delete crontab blank line

after executing the sed-i command above, crontab -l will see an extra line of white space. If you feel awkward, you can delete the blank line with the following command: sed.

 sed -i '/^$/d' /var/spool/cron/root