Run terminal commands even with error

ymurawski

New Member
Joined
Dec 19, 2022
Messages
2
Reaction score
0
Credits
19
Hi,
i have a cronjob to update my containers. Sometimes it happens that there is an error in the command . Is there any way to ignore the error and go on with the rest of the terminal command ?

For Example:
50 3 * * * sudo docker stop wg-easy && sudo docker rm wg-easy && sudo docker pull weejewel/wg-easy && docker run -d --name=wg-easy

sometimes it happens that the docker isnt recongnized by the command "sudo docker rm wg-easy" and the command will stop there.

Thanks for any ideas
 


JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,704
Reaction score
2,471
Credits
13,677
&& is a conditional operator.
The command to the right of && will only run if the command to the left completes successfully.

So if you want ALL of the commands to run, regardless of whether or not another command fails, simply separate them with ; instead of using &&.
e.g.
Code:
50 3 * * * sudo docker stop wg-easy; sudo docker rm wg-easy; sudo docker pull weejewel/wg-easy; docker run -d --name=wg-easy

That should do the trick!
 
Last edited:
OP
Y

ymurawski

New Member
Joined
Dec 19, 2022
Messages
2
Reaction score
0
Credits
19
&& is a conditional operator.
The command to the right of && will only run if the command to the left completes successfully.

So if you want ALL of the commands to run, regardless of whether or not another command fails, simply separate them with ; instead of using &&.
e.g.
Code:
50 3 * * * sudo docker stop wg-easy; sudo docker rm wg-easy; sudo docker pull weejewel/wg-easy && docker run -d --name=wg-easy

That should do the trick!
Works perfectly thanks :)
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
5,925
Reaction score
4,414
Credits
43,540
If you want to automatically have your images and containers updated I think you might as well switch to podman since it supports that.
 
Last edited:

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
9,043
Reaction score
7,693
Credits
73,791

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
8,628
Reaction score
7,587
Credits
35,291
Moved to Command Line

Chris Turner
wizardfromoz
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Staff online

Members online


Top