Computing.Net > Forums > Unix > Smartrm and backup cript needed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Smartrm and backup cript needed

Reply to Message Icon

Name: oxi
Date: November 4, 2002 at 22:32:04 Pacific
OS: UNIX
CPU/Ram: Sol 6
Comment:

Hi!
I have two questions. It's already 1.15 AM :( can't solve it. May be somebody will help?

1)

Write a sript caled smartrm which will accept an unlimited number pf filename extensions and will remove all file in the curent dir with thouse extentsions. For example:
smartrm o c i
will remove all files in the curent dir with .o .c .i extentions. If no arguments provided print error.
I have this, but it only removes files with first extention
*************
#!/bin/ksh

integer cn[$#]
integer i

if(($# == 0))
then
print "Error"
exit 1
fi
IFS='.'
for number in $*
do
rm *.$*"

done
*******
2)

Second problem is harder:
write a script called backup that will backup a dir containing C files. This script will accept the name of dir. If the dir already exitst (with _bak extention) print error. Use the curent dir as a defaut dir. Given the name of a dir the script will crate a new dir with '_bak' appendet to the name of the dir.
Thanx in advance,
oXide



Sponsored Link
Ads by Google

Response Number 1
Name: jimbo
Date: November 4, 2002 at 22:47:37 Pacific
Reply:

Problem 1 solution:

#! /bin/ksh
if [[ $# -eq 0 ]] ; then
print "Error"
exit 1
fi

for type in "$@" ; do
rm *.$type
done

-jim



0

Response Number 2
Name: oxi
Date: November 4, 2002 at 23:03:20 Pacific
Reply:

Thanks Jim!!

It realy works :)

May be you could help me to solve the second problem?

That would be very nice of you.

oXide


0

Response Number 3
Name: jimbo
Date: November 5, 2002 at 04:43:21 Pacific
Reply:

Problem 2 solution (untested)

#! /bin/ksh

# Test for an argument
if [[ $# == 0 ]] ; then
print "Argument needed: directory name"
exit 1
fi

# Strip the ending "/" on the directory
case $1 in
*/ ) DIR=${1%*/} ;;
* ) DIR=$1 ;;
esac

# Test that entered directory exists
if [[ ! -d "$DIR" ]] ; then
print "Directory does not exist."
exit 1
fi

# Check for a backup of the entered directory
if [[ -d "${DIR}_bak" ]] ; then
print "Backup already exists."
fi

# Make the backup directory and copy files to it
mkdir ${DIR}_bak
cp ${DIR}/*.c ${DIR}_bak

-jim


0

Response Number 4
Name: jimbo
Date: November 5, 2002 at 04:46:55 Pacific
Reply:

Forgot the "exit 1" after the Check for a backup of the entered directory:

if [[ -d "${DIR}_bak" ]] ; then
print "Backup already exists."
exit 1
fi

-jim


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Smartrm and backup cript needed

Help needed with resh/rsh remote command www.computing.net/answers/unix/help-needed-with-reshrsh-remote-command/2295.html

Need help with a search and replace logi www.computing.net/answers/unix/need-help-with-a-search-and-replace-logi/3296.html

NEED TO PRINT HTML IN UNIX! HELP! www.computing.net/answers/unix/need-to-print-html-in-unix-help/2834.html