Find the answer to your Linux question:
Results 1 to 3 of 3
Dear all, How does a shell script work whith related t program execution. Ex: when i have to delete a bunch of files before a backup. Will the backup commands ...
  1. #1
    Just Joined!
    Join Date
    Apr 2009
    Posts
    17

    shell scripts

    Dear all,

    How does a shell script work whith related t program execution.

    Ex: when i have to delete a bunch of files before a backup. Will the backup commands fired AFTER the files are removed using the rm command or should i check the exit status of the rm command before i do the backup?

    rm ./*.log
    tar cvf ./backup.tar ./*

    How can i make sure the tar command is executed after the rm command?

    cheers

  2. #2
    Linux Engineer Kieren's Avatar
    Join Date
    Aug 2007
    Location
    England
    Posts
    845
    In relation to time the rm command will run and complete (either successfully or with an error) and then the tar command will be executed. They will not run at the same time

    However, in programming terms it would be a good idea to check that the rm command completed successfully before you tar as error checking will stop any problems occurring later due to previous errors
    Linux User #453176

  3. #3
    ARH
    ARH is offline
    Just Joined!
    Join Date
    Apr 2009
    Posts
    11

    Arrow

    Quote Originally Posted by earlysame55 View Post
    Dear all,

    How does a shell script work whith related t program execution.

    Ex: when i have to delete a bunch of files before a backup. Will the backup commands fired AFTER the files are removed using the rm command or should i check the exit status of the rm command before i do the backup?

    rm ./*.log
    tar cvf ./backup.tar ./*

    How can i make sure the tar command is executed after the rm command?

    cheers
    if rm execute successfully, It return 0 and you can get it's retuned value by $? variable. following script run the tar command if rm execute successfully :


    rm ./*.log
    if [ $? -eq 0 ]
    then
    tar cvf ./backup.tar ./*
    fi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...