質問

I'd like to set up a backup.sh file that executes these two commands when run:

cp ~/SURV/plugins/iConomy/accounts.mini ~/backups/

cp ~/SURV/plugins/CoreProtect/database.db ~/backups/

I want it to just run these 2 commands and display the text "Backups creados con éxito!"

役に立ちましたか?

解決

Use && between commands: it will execute the next command only if the previous command execution is a success. The || does the inverse => echo "error" will be displayed if one of the both cp fails.

#!/bin/sh 
cp ~/SURV/plugins/iConomy/accounts.mini   ~/backups/ &&
cp ~/SURV/plugins/CoreProtect/database.db ~/backups/ &&
echo "Backups creados con éxito!" ||
echo "error"

You can also add -v option to the cp command for more visibility.

In order to make your script executable you have to do:

chmod +x backup.sh 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top