- Joined
- May 18, 2007
- Messages
- 5,844
- Reaction score
- 5,250
Hey guys, I'm doing a bit of Linux shell scripting but shell scripting isn't a strong point of mine. What I'm doing is I'm running an Apache server on CentOS 6.5 and I'm using a non-default directory for storing my files. I want to have a script that when executed with a file as a variable, the file is copied to this directory and the httpd service is started on the condition that the file is found. I then want the Apache server to retrieve this file from the non-default directory and for a message to be echoed back onto the terminal that the file was either successfully or unsuccessfully retrieved.
As you can see I've made a start but I haven't got the copy command or the start httpd service command embedded in the condition. What's the most straightforward way to do this?
As you can see I've made a start but I haven't got the copy command or the start httpd service command embedded in the condition. What's the most straightforward way to do this?
Code:
# This script will check to see if a file exists and if so,# copy the file in to the [DIRECTORY] directory. From here it
# will be executed after starting the Apache daemon, httpd.
# The script will then inform the user whether or not the file
# was successfully retrieved.
[ -f $1 ] && echo "File $1 exists, now copying file to [DIRECTORY] and starting httpd daemon..." || echo "File $1 does not exist. Please try again."
cp -rv $1 [DIRECTORY]
start httpd service