Results 1 to 6 of 6
Hi guys, just having a bit of trouble using the "if" command in a script.
i want a script that tests to see if a directory exists, and then if ...
- 02-24-2009 #1
problems with if/else
Hi guys, just having a bit of trouble using the "if" command in a script.
i want a script that tests to see if a directory exists, and then if so, copy files from that directory to another drive. here's how i'm going about it, but it isn't working.
any ideas?
Code:if test -d /usr/people/cranial then echo "found Synergy Cranial. Preparing to back up" cp /usr/people/cranial/cranialData /mnt/usbdisk/cranialData echo "done" else echo "synergy cranial not installed, skipping step" fi
You know, aliens are going to come to earth in 50 years and kill the hell out of us for DDoSing their networks with this SETI crap
registered linux user #388463
- 02-24-2009 #2
Nothing is wrong in your code except cp command. If you are copying files then use wildcard. Use -r option for folder.
To copy files from cranialData to other :
If you want to copy cranialData folder to /mnt/usbstick :Code:cp /usr/people/cranial/cranialData/* /mnt/usbdisk/cranialData
Code:cp -r /usr/people/cranial/cranialData /mnt/usbdisk
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 02-24-2009 #3
thanks very much, i'll give this a try
You know, aliens are going to come to earth in 50 years and kill the hell out of us for DDoSing their networks with this SETI crap
registered linux user #388463
- 02-24-2009 #4
no joy i'm afraid. i just get an error message saying:
if: Expression Syntax
any ideas?You know, aliens are going to come to earth in 50 years and kill the hell out of us for DDoSing their networks with this SETI crap
registered linux user #388463
- 02-24-2009 #5
I copied/paste your code ( changed folder_path only ) and its working fine here.
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 02-26-2009 #6Linux Newbie
- Join Date
- Feb 2009
- Posts
- 99
are you using bash env or csh env?
because in bash --> if then else fi
in csh --> if then else if
and try
#!/bin/bash
if [ -d /usr/people/cranial ]
then
echo "found Synergy Cranial. Preparing to back up"
cp -r /usr/people/cranial/cranialData /mnt/usbdisk/cranialData
echo "done"
else
echo "synergy cranial not installed, skipping step"
fi


Reply With Quote