0

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)

2 Answers 2

0

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

1
  • 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. Aug 6, 2013 at 13:36
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .