Help with backup script in C-shell

Hi I am trying to back up files with cshell script .And I have to pass the size of the files,the backup directory and the file
Could you help me with advises ,and am I useing find right
thanks

#!/bin/csh
if( $2 =="") then
echo "Please provide correct parameters"
echo "corect call is:  $0 <size> <target_directory> <filename list>"
exit
endif
if (!(find ./-name "$2")) 
then
echo "File with the same name exist allready"
exit
endif

What are your requirements?

Why not just use tar command, that would make life much easier

tar -cvf <filename.tar> * or some path name

Thanks ,because I have to check if the tar directory exist or not

tar does that of course, since it's hardly possible to create a file in a nonexistent directory. Even if you write it in csh it'd make sense to use tar somehow.

Why are you using csh, anyway? Any other shell would be better. If you absolutely insist on it, here's how you check for a directory in csh:

#!/bin/csh

set DIR="asdf"
if ( -d "$DIR" ) then
        echo exists
endif

Thanks ,but it doesn work
prints Empty if

 
#!/bin/csh
if( $2 =="") then
echo "Please provide correct parameters"
echo "corect call is:  $0 <size> <target_directory> <filename list>"
exit
endif
if ( -d "$2 ")
then
echo "File with the same name exist allready"
exit
endif
 
 

You are beginning to discover for yourself just what's wrong with the C-shell. I think you missed some spaces, but the ad-hoc parser throws a wobbly and returns an error that has nothing to do with the problem.

 
#!/bin/csh
if ( $2 == "" )
then
echo "Please provide correct parameters"
echo "corect call is:  $0 <size> <target_directory> <filename list>"
exit
endif
if ( -d "$2" )
then
echo "File with the same name exist allready"
exit
endif
 
 
1 Like

You might as well test all the parameters at once and print "Usage: ....", something like:

if [ $# -lt 3 -o 0$1 -lt 1 -o ! -d "$2" -o ! -f "$3" ]
then
 echo "
Usage: ${0##*/} <size> <target_directory> <filename list>
" >&2
 exit 1
fi