ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
when i am running scripts it is giving error
./dist_auar_pb.sh: line 156: [: /psoft/batch/fsdev/outbound/auar/atl/archive/AUARCPPSF05.120504: binary operator expected
for code
if [ -f $ARC_DIR/${EXTRACT}* ]
then
find $ARC_DIR/${EXTRACT}* -mtime +45 -exec rm {} \;
fi
but clone copy of this script working fine for same coding
y this??
plz tell me solution what should i do with this script why only this script giving error and not clone scripts
presumably the *'s are causing multiple file names to be returned. You can't ask if multiple files exist, nor can you find them. when the script works, there is probably only 0 or 1 file that exists.
Your code doesn't really make sense, you seem to want to say "if there are any files matching this pattern, then go find them and delete them". Why bother checking first? Just delete all the ones that are found. If none are found, none are deleted, so you get the same result, but in much less code.
@chris
yes that true..
i think ir wrks bz that tim having one file in folder and i run script..
and about this script when i run it that time more than one files were there..
thats y it failed...
so do you know how i should check for multiple file??
should i use for??
Please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
In addition to the above comments, the syntax of the find command is wrong.
You start by giving find one or more starting directories, not files, and various criteria for matching the contents of those directories. Finally you supply an action for find to take when it matches something (-print by default).
One of the actions available in gnu find is "-delete", BTW.
So you really want something more like this:
Code:
find "$ARC_DIR" -type f -name "<*globpattern*>" -mtime +45 -delete
Since I don't know exactly what your "$EXTRACT" variable contains, I'm leaving it out of the above for the time being. You'll have to figure out how to apply it correctly yourself. Hint: you can give it multiple entries like "-name" at once.
Finally, QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.