Nested case: rsync command not found


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nested case: rsync command not found
# 1  
Old 09-28-2015
Nested case: rsync command not found

Hello!

Below my first bash script. As you can see i build 2 nested cases. The second one (sync databases) is working fine. Bu the first one (sync datadirs) is not working. It says: rsync: command not found. However when i move the rsync command to the top of the script its working. So i suppose there's something wrong in my script. Can somebody tell me what's wrong?

Regards,
Bas

--- Script ---
Code:
#!/bin/bash

LOCAL_PATH=""
LOCAL_DB=""
LOCAL_DB_USER=""
LOCAL_DB_PASSWORD=""

STAGING_SSH_USER=""
STAGING_SSH_HOST=""
STAGING_PATH=""
STAGING_DB=""
STAGING_DB_USER=""
STAGING_DB_PASSWORD=""

LIVE_SSH_USER=""
LIVE_SSH_HOST=""
LIVE_PATH=""
LIVE_DB=""
LIVE_DB_USER=""
LIVE_DB_PASSWORD=""

read -p "What to do?
	(1) Sync datadirs
	(2) Sync database" choice1

case "$choice1" in
	1 )
		read -p "Sync datadirs:
			(1) pull staging -> local
			(2) pull live -> local
			(3) push local -> staging" choice2

		case "$choice2" in
			1 )
				TYPE=pull-datadirs
				ENV="staging"
				SSH_USER=$STAGING_SSH_USER
				SSH_HOST=$STAGING_SSH_HOST
				PATH=$STAGING_PATH
				;;
			2 )
				TYPE=push-datadirs
				ENV="live"
				SSH_USER=$LIVE_SSH_USER
				SSH_HOST=$LIVE_SSH_HOST
				PATH=$LIVE_PATH
				;;
			3 )
				TYPE=push-datadirs
				ENV="staging"
				SSH_USER=$STAGING_SSH_USER
				SSH_HOST=$STAGING_SSH_HOST
				PATH=$STAGING_PATH
				;;
			* )
				echo "invalid"
				exit
				;;
		esac
		;;
	2 )
		read -p "Sync database:
			(1) pull staging -> local
			(2) pull live -> local
			(3) push local -> staging" choice2

		case "$choice2" in
			1 )
				TYPE=pull-database
				ENV="staging"
				SSH_USER=$STAGING_SSH_USER
				SSH_HOST=$STAGING_SSH_HOST
				DB=$STAGING_DB
				DB_USER=$STAGING_DB_USER
				DB_PASSWORD=$STAGING_DB_PASSWORD
				;;
			2 )
				TYPE=pull-database
				ENV="live"
				SSH_USER=$LIVE_SSH_USER
				SSH_HOST=$LIVE_SSH_HOST
				DB=$LIVE_DB
				DB_USER=$LIVE_DB_USER
				DB_PASSWORD=$LIVE_DB_PASSWORD
				;;
			3 )
				TYPE=push-database
				ENV="staging"
				SSH_USER=$STAGING_SSH_USER
				SSH_HOST=$STAGING_SSH_HOST
				DB=$STAGING_DB
				DB_USER=$STAGING_DB_USER
				DB_PASSWORD=$STAGING_DB_PASSWORD
				;;
			* )
				echo "invalid"
				exit
				;;
		esac
		;;
	* )
		echo "invalid"
		exit
		;;
esac

# Pull datadirs
if [ $TYPE == 'pull-datadirs' ] ; then
	echo "Start syncing fileadmin/user_upload and uploads/ from $ENV to local"
	rsync -avzhn --include='fileadmin/' --include='fileadmin/user_upload/***' --include='uploads/***' --exclude='*' --progress --delay-updates --delete --stats $SSH_USER@$SSH_HOST:$PATH $LOCAL_PATH
	echo "Completed!"
fi

# Push datadirs
if [ $TYPE == 'push-datadirs' ] ; then
	echo "Start syncing fileadmin/user_upload and uploads/ from local to $ENV"
	rsync -avzhn --include='fileadmin/' --include='fileadmin/user_upload/***' --include='uploads/***' --exclude='*' --progress --delay-updates --delete --stats $LOCAL_PATH $SSH_USER@$SSH_HOST:$PATH
	echo "Completed!"
fi

DB_FILE=$DB$(date +.%d.%m.%y).sql.gz
DB_FILE_LOCAL=$LOCAL_DB$(date +.%d.%m.%y).sql.gz

# Pull database
if [ $TYPE == 'pull-database' ] ; then
	echo "Make dump from $ENV"
	ssh $SSH_USER@$SSH_HOST "mysqldump --user=$DB_USER --password=$DB_PASSWORD $DB" | gzip > ./$DB_FILE
	echo "Import to local"
	gzip -dc < ./$DB_FILE | mysql --user=$LOCAL_DB_USER --password=$LOCAL_DB_PASSWORD $LOCAL_DB
	echo "Completed!"
fi

# Push database
if [ $TYPE == 'push-database' ] ; then
	echo "Make dump from local"
	mysqldump --user=$LOCAL_DB_USER --password=$LOCAL_DB_PASSWORD $LOCAL_DB > $DB_FILE_LOCAL
	echo "Import to $ENV"
	ssh $SSH_USER@$SSH_HOST "mysql --user=$DB_USER --password=$DB_PASSWORD $DB" < ./$DB_FILE_LOCAL
	echo "Completed!"
fi


Last edited by Franklin52; 09-28-2015 at 08:26 AM.. Reason: Replaced icode tags with regular code tags
# 2  
Old 09-28-2015
Please use code tags as required by forum rules!

You modify the search PATH: PATH=$STAGING_PATH and thereafter rsync is no more found...

---------- Post updated at 12:50 ---------- Previous update was at 12:48 ----------

Usually, you add sth to the PATH like PATH="$PATH:$STAGING_PATH"
# 3  
Old 09-28-2015
Ah of course tnx!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

The Shell lost the inverted comma in a nested ssh command

Hi, i want use this Comand for my psql request sh ssh -o StrictHostKeyChecking=no rootatemailaddress.de sudo psql -U postgres -c "select pg_terminate_backend(pid) from pg_stat_activity where datnam=\'$DB\';"'" but the shell lost the inverted comma for datnam=\'$DB\'. The request deliver... (2 Replies)
Discussion started by: peterpane007
2 Replies

2. Shell Programming and Scripting

Using shell command need to parse multiple nested tag value of a XML file

I have this XML file - <gp> <mms>1110012</mms> <tg>988</tg> <mm>LongTime</mm> <lv> <lkid>StartEle=ONE, Desti = Motion</lkid> <kk>12</kk> </lv> <lv> <lkid>StartEle=ONE, Source = Velocity</lkid> <kk>2</kk> </lv> <lv> ... (3 Replies)
Discussion started by: NeedASolution
3 Replies

3. Shell Programming and Scripting

How can I write nested command substitutions?

Hello How can write the nested command substitutions? echo `expr substr $x 1 expr ${#x} - 1` the above code is not working! Thanks in advance Regards Chetanz (5 Replies)
Discussion started by: Chetanz
5 Replies

4. Shell Programming and Scripting

Nested case inside awk

please let me know if the below code could be written efficiently inside single awk case "$INP" in ksh) cat catalog | awk 'BEGIN {FS=",";} { print $2 } END {}' ;; pset) cat catalog | awk 'BEGIN {FS=",";} { print $3 } END {}' ;; dml) cat catalog | awk 'BEGIN {FS=",";} {... (2 Replies)
Discussion started by: cvsanthosh
2 Replies

5. Shell Programming and Scripting

Nested case

Hi there, I have nested case in my script. I am asking user, want to continue? if user press y/Y then my inner case should continue, rather than that my code start from beginning. I would like to continue my inner case until user press n or N. Is any one tell me how can I do? Thanking You,... (2 Replies)
Discussion started by: kasparov
2 Replies

6. Shell Programming and Scripting

sending email in case of file not found

Hi, In the shell script, i want to do sftp and go to a directory and check if a particular file is present, if not i send an email with some error message. Please guide me about how i could achieve it...." (1 Reply)
Discussion started by: sJohn
1 Replies

7. Shell Programming and Scripting

If-statement nested in case

I'm trying to write case statements with 'if statements' embedded inside of them. I'm using the korn shell but it's not functioning. If I want to see if a string exists in a file and then perform an action, what would be the best way to do this? For file "asg51fin" to delete a line if a... (1 Reply)
Discussion started by: dazeman27
1 Replies

8. Shell Programming and Scripting

Nested Case in UNIX script

Hi I wanted to know if we can write a nested case in UNIX script. Something like following - Case ${sDB} in Srvr1) case ${sSchema} Sch1) DBusr=Username1 DBPwd=Pwd1 ;; Sch2) DBusr=Username2 ... (1 Reply)
Discussion started by: sumeet
1 Replies

9. UNIX for Dummies Questions & Answers

Nested Echo Command Help

I am doing below : $HOST_NAME1="webisstg70" $count=1 $echo $HOST_NAME1 $count webisstg70 1 $HOST_NAME="" $HOST_NAME=`echo '$HOST_NAME'${count}` $echo $HOST_NAME HOST_NAME1 $NODE_NAME=`echo $`echo ${HOST_NAME}`` I get below error message (2 Replies)
Discussion started by: findprakash
2 Replies

10. Shell Programming and Scripting

how can i check in csh if command found or not found ?

hello all im trying to use in sun Solaris the information received from the top command now i several machines that dont have install the top program so when im running the script im geting error saying after im running this code : set MemoryInfo = `top | grep Memory` if (... (2 Replies)
Discussion started by: umen
2 Replies
Login or Register to Ask a Question