Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm not a (web)server expert, so I need a little help with the following question. I realy couldn't find a answer via Google, probably because I'm using the wrong keywords.

I would like to know if it's possible to create a file somewhere on the server that I could use/call to execute multiple commands and which I can 'feed' some extra parameters like source, destination and the group/owner of the files on the destination.

What I would like to create is a file that duplicates the content of a folder, places it in another folder and than set the group/owner of the files/folders and probably also chmod some folders within the destination.

I know how to use this command apart from each other, but is it possible to group all of this commands in a single file and execute this file with some parameters?

The server is running on CentOS 6.0 (64-bit)

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

You can write a script using Bash for example which will execute all your commands and logic in sequence. There's a lot of great material on the Internet on Bash scripts.

Don't forget to set execute permission on the script file (chmod +x filename.sh) and execute it either using full-path or starting with ./filename.sh

share|improve this answer
    
Thank you. Didn't know they where called bash scripts. I found a lot of information on Google about writing custom bash scripts with arguments. –  Mike de Vrind Aug 6 '13 at 13:36
add comment

I know how to use this command apart from each other, but is it possible to group all of this commands in a single file and execute this file with some parameters?

Of course it possible. You may use any script language bash/perl/php/ruby/etc whatever you like/know. It could be something like the following

#!bin/bash

src=$1
dst=$2
uid=$3
gid=$4
action=$5

if [ $# -le 4 ]
then
    echo "Usage: script.sh <source> <destination> <user owner> <group owner> <action>"
    exit
fi

if [ ! -d "${src}" ]
then
    echo "Source folder does not exist. Before proceed you must create it"
    exit
fi

...

case "$action" in
create)
   command1;
   command2;
   command3; 
;;  
delete)
   command1;
   command2;
   command3; 
;;
esac
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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