1

I am using Jenkins to build project. I am able to build Project. I need to copy the war file in target location. I can copy the .war file using cp source_file_location target_file_location it will do the job. But I want to check if the file already exist show message old file found then delete the old file and copy the new file in target location.

and zip the target location folder and copy in x place.

I am really sorry. It seems I have just given the requirement. I really don't know how to write shell script except some basic command. can any body help me?

1 Answer 1

1

Ok, then just some hints of the commands that you will need. This should be enough to create your first bash script.

But I want to check if the file already exist

Take a look to the test command (or the equivalent [ -f file_exists ]. As an example:

if [ ! -f /tmp/foo.txt ]; then
    echo "File not found!"
fi

show message old file found

echo "My message"

then delete the old file

 rm file (or -r for directory)

and copy the new file in target location.

This part think you already know ho do it

If you have any doubt about any command, just try to consult the command manual. In general it's very easy and straightforward. Following is a link to a good bash programming tutorial.

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.