- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shellscript help needed
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 05:59 PM
11-26-2001 05:59 PM
Shellscript help needed
I am having some problem with the script.....
I have attached the shell script with all the details.....
This script is prepared by robin.....
I need your help to solve this problem....
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 06:14 PM
11-26-2001 06:14 PM
Re: Shellscript help needed
Is it the
|ARGS RM
that is causing the problem?
If so, you'll get an error:
"`|' is not expected."
Just delete that line and try again.
Apologies if I have not understood your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 06:23 PM
11-26-2001 06:23 PM
Re: Shellscript help needed
It looks to me like the following section of code is missing a 'do' keyword.
find /home/rajkumar/J??/* -name "X_*" -mtime +3 | while read FILE ;
rm $FILE && logger "$0 : $FILE deleted"
COUNT=$(expr $COUNT + 1)
done
Rob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 06:23 PM
11-26-2001 06:23 PM
Re: Shellscript help needed
...
exit 1
fi
|ARGS RM
COUNT=0
....
what's the line with the | ? that could be the erring line...
could please elaborate more on what the script basically does?
d_b
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 06:28 PM
11-26-2001 06:28 PM
Re: Shellscript help needed
Thank you for your replies...
similar to this script I have attached the other script with all the details..
Consider this is actual script...Thanking you....
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 06:58 PM
11-26-2001 06:58 PM
Re: Shellscript help needed
Second, find will give you all teh "X_*.DAT" files as well, you can eleimiate them by changing
find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | while read FILE ; do
to
find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v "X_" | while read FILE ; do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 07:08 PM
11-26-2001 07:08 PM
Re: Shellscript help needed
Thank you for your reply....
We cannot hardcoded "X_" in the script..That "database.props" will updated by the user from some other application...Some times user many change the it to "Y_".If they change it to "Y_" ,internally this "database.props" will automatically update to "Y_".so at that time it will be a problem..So we have to avoid it by getting the value itself from the "database.props" file..Is it possible in that way????
Raj...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 07:26 PM
11-26-2001 07:26 PM
Re: Shellscript help needed
You already have a BACK_FILE_EXT=X_ in your props file.
You can do this:
find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v ${BACK_FILE_EXT} | while read FILE ; do
Remember that once you change BACK_FILE_EXT from X_ to Y_, all files with X_ will be deleted when you run this script. Maybe you should consider:
find $DIR -name *${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v "_" | while read FILE ; do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 08:19 PM
11-26-2001 08:19 PM
Re: Shellscript help needed
When i placed | grep -v {BACK_FILE_EXT}
I am facing the error..
and When i replaced with
| grep -v "_" it is displaying the DAT files along with CDR files also....
any solution please..
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 08:46 PM
11-26-2001 08:46 PM
Re: Shellscript help needed
" grep -v ${BACK_FILE_EXT} "
find is working fine here in eliminating the cdr files.
I dont know whats going wrong on your end, but you can try this:
find $DIR -name *${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v "_" | grep -v "CDR" | while read FILE ; do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 09:32 PM
11-26-2001 09:32 PM
Re: Shellscript help needed
If i placed like this
1)|"grep -v ${BACK_FILE_EXT}"
2)|"grep -v $ "_""
If i placed like this |grep -v "_" i am getting CDR files as well as DAT files only....but "X_" are not displaying...
Any solution ???
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 10:01 PM
11-26-2001 10:01 PM
Re: Shellscript help needed
you've got file*.DAT, X_file*.DAT and file*.CDR.
Now, which of these do you want to delete if they are older than 3 days?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2001 10:47 PM
11-26-2001 10:47 PM
Re: Shellscript help needed
The script is attached again...
In the "database.props" file i am having only "FILE_NAME=DAT" extension and "RETAIN_PEND=<3 or 4 days>
so i if execute the script it should collect only "DAT" extension files that were not starting with "X_<....>.DAT" and it should be deleted from the value specified in the "RETAIN_PEND" parameter........
Other than that we should not delete all the files like "
The files
Please revert back to me if my explanation is wrong......
RA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 01:40 AM
11-27-2001 01:40 AM
Re: Shellscript help needed
will give you
find . -name "*DAT" -mtime +3 | grep -v "_"
will give you
Please try this. I don't see how you can be getting .CDR files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 02:49 AM
11-27-2001 02:49 AM
Re: Shellscript help needed
When i execute below one i am getting only "DAT" &"CDR" files...
#find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v "_" | while read FILE ; do
But when i execute the below in the script ,It display nothing!!!!!!!!!
#find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v "${BACK_FILE_EXT}" | while read FILE ; do
I dont want to hardcoded "_" or "X_" in the scripts..Every thing i should read from the parameter....
Is it possible.....
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 02:52 AM
11-27-2001 02:52 AM
Re: Shellscript help needed
Can you echo them and check?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 03:34 AM
11-27-2001 03:34 AM
Re: Shellscript help needed
When i execute this below script,Its displaying null;
#################
export CONFIG_DIR=/home/rajkumar/house/input
export PROPERTY_FILE=database.props
gw=$CONFIG_DIR/$PROPERTY_FILE
echo $gw
set | grep BAC_ $gw | cut -d= -f2 | while read DIR ; do
if [ ! -d "$DIR" ] ; then
logger "$0: directory, $DIR not found."
fi
COUNT=0
find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v "$BACK_FILE_EXT*" | while read FILE ; do
echo $FILE_NAME
echo $RETAIN_PEND
echo $BACK_FILE_EXT
#rm $FILE && logger "$0: file $FILE deleted."
COUNT=$(expr $COUNT + 1)
done
if [ "$COUNT" -gt 0 ] ; then
logger "$0: for directory $DIR, $COUNT file(s) removed."
else
logger "$0: for directory $DIR, no matching files found."
fi
done
exit 0
####################################
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 03:42 AM
11-27-2001 03:42 AM
Re: Shellscript help needed
Share and enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2001 05:57 AM
11-27-2001 05:57 AM
Re: Shellscript help needed
First, decide whether PROPERTY_FILE should be PROPERTY.PROPS or database.props.
Second, source the property file in your script like so:
-------------
gw=$CONFIG_DIR/$PROPERTY_FILE
. gw
-------------
If, after doing this, your echos are still null, you may need to export the values in your properties file.
That is, instead of
FILE_NAME=DAT
you'll have to do a
export FILE_NAME=DAT
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2001 04:53 AM
12-04-2001 04:53 AM
Re: Shellscript help needed
Still the same problem occuring....
Thank you all for your help..
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2001 05:43 AM
12-04-2001 05:43 AM
Re: Shellscript help needed
The only thing I can see wrong is that the $gw file is not being sourced. You don't need the "set" either, since you're grepping a file.
One minor point is that you need a "continue" statement when a $DIR is not found, to abort the current loop - this is how I see the script looking at the moment:
==========================================
export CONFIG_DIR=/home/rajkumar
export PROPERTY_FILE=database.props
gw=$CONFIG_DIR/$PROPERTY_FILE
echo $gw
. $gw
grep BAC_ $gw | cut -d= -f2 | while read DIR ; do
if [ ! -d "$DIR" ] ; then
logger "$0: directory, $DIR not found."
continue
fi
COUNT=0
find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v "$BACK_FILE_EXT*" | while read FILE ; do
echo $FILE_NAME
echo $RETAIN_PEND
echo $BACK_FILE_EXT
#rm $FILE && logger "$0: file $FILE deleted."
COUNT=$(expr $COUNT + 1)
done
if [ "$COUNT" -gt 0 ] ; then
logger "$0: for directory $DIR, $COUNT file(s) removed."
else
logger "$0: for directory $DIR, no matching files found."
fi
done
exit 0
==========================================
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2001 05:59 AM
12-04-2001 05:59 AM
Re: Shellscript help needed
try the script below. if it won't work, it's all your fault, it works fine for me :P~
export CONFIG_DIR=/root/test
export PROPERTY_FILE=database.props
gw=$CONFIG_DIR/$PROPERTY_FILE
. $gw
set | cat $gw | cut -d= -f1
cat $gw | grep "BAC_" | cut -d= -f2 | while read DIR ; do
if [ ! -d "$DIR" ] ; then
logger "$0: directory, $DIR not found."
fi
COUNT=0
find $DIR -name "*${FILE_NAME}" -mtime +${RETAIN_PEND} | grep -v "$BACK_FILE_EXT*" | while read FILE ; do
rm $FILE && logger "$0: file $FILE deleted."
COUNT=$(expr $COUNT + 1)
done
if [ "$COUNT" -gt 0 ] ; then
logger "$0: for directory $DIR, $COUNT file(s) removed."
else
logger "$0: for directory $DIR, no matching files found."
fi
done
exit 0