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
 


&& 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:
&& 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 :)
 
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:
Moved to Command Line

Chris Turner
wizardfromoz
 

Staff online


Top