I have the following shell script which writes volumes in a find command to a file, and loads that file into a mysql database:
# find all the paths and print them to a file
sudo find $FULFILLMENT/ > $FILE
sudo find $ARCH1/ >> $FILE
sudo find $ARCH2/ >> $FILE
sudo find $MASTERING/ >> $FILE
# load the file into the mysql database, `files`, table `path`
/usr/local/bin/mysql -u root files -e "TRUNCATE path"
/usr/local/bin/mysql -u root files -e "LOAD DATA INFILE '/tmp/files.txt' INTO TABLE path"
TRUNCATE is to be used to delete all the old entries before adding the new. However, if any of the find commands don’t work (for example, if the volume isn’t accessible), I want it to skip on the two mysql commands. How would I modify the above script to do this?
This will execute your two
mysqlcommands only if all thefindcommands succeed:The
&&operator causes the command on the RHS to run only if the command on the LHS succeeds. The{ ... }groups the twomysqlcommands into one compound command, so either both run (if the lastfindsucceeds) or neither does (if the lastfinddoes not succeed).You can use this if there is more to your script that should run whether or not the
finds succeed and themysqlcommands run.