First, never tell us: "i use your command and make this script but it wouldn't work"! Show us the exact output from running the script that explains to us exactly what didn't work. If you don't show us how it isn't working, it makes it a huge guessing game for all of us (especially those of us who are using a different operating system and shell than you're using).
Second, there is a HUGE difference between running a program and feeding its output to awk as RudiC suggested with:
and running a program, saving its output in a variable, executing a fixed string, and feeding the results of the command named by that string to awk as your code is doing:
Why are you storing the output from ls in a variable.
Third: You have an extraneous single quote before the -F option to awk.
And, fourth: I don't see how this script is going to work if you use ls -l instead of ls without the -l option. (With ls -l output, $1 in awk is never going to match Full nor level.)
Please try running your script more like RudiC suggested:
This User Gave Thanks to Don Cragun For This Post:
You assigned the ls result to the "output" variable. To get at its contents, the shell needs to expand it: $output, to keep the shell from swallowing redundant spaces etc, quote it: "$output". To pipe it into sth. else, echo it: echo "$output".
Why don't you pipe ls's results immediately, as I alluded in my post?
Could you please try following code and let us know if this helps.
Thanks,
R. Singh
Thank you dear Singh.
but your command doesn't work.
Quote:
Originally Posted by Don Cragun
First, never tell us: "i use your command and make this script but it wouldn't work"! Show us the exact output from running the script that explains to us exactly what didn't work. If you don't show us how it isn't working, it makes it a huge guessing game for all of us (especially those of us who are using a different operating system and shell than you're using).
Second, there is a HUGE difference between running a program and feeding its output to awk as RudiC suggested with:
and running a program, saving its output in a variable, executing a fixed string, and feeding the results of the command named by that string to awk as your code is doing:
Why are you storing the output from ls in a variable.
Third: You have an extraneous single quote before the -F option to awk.
And, fourth: I don't see how this script is going to work if you use ls -l instead of ls without the -l option. (With ls -l output, $1 in awk is never going to match Full nor level.)
Please try running your script more like RudiC suggested:
dear Don . i use the ssh to get the directory info. so i had to run and put it in a variable.
i use your shell command and it work but not the way i want it.
result:
i want just return a value. your shell script return a value for each directory name.
let me put it this way:
i want check the directory for backup status. valid backup lifetime is less than two days. now
if the script return the "10" i found out i have a full backup which is valid.
if the script return the "5" i found out i have a level backup which is valid.
in other wise i dont have a valid backup file.
Quote:
Originally Posted by RudiC
You assigned the ls result to the "output" variable. To get at its contents, the shell needs to expand it: $output, to keep the shell from swallowing redundant spaces etc, quote it: "$output". To pipe it into sth. else, echo it: echo "$output".
Why don't you pipe ls's results immediately, as I alluded in my post?
thank you dear RudiC.
i use the ssh to get the directory info. so i had to run and put it in a variable.
I don't see the necessity to use a variable if you run an ssh command. From what you showed in post #1, there is an entire directory listing to be processed, and you did not specify the output format desired.
Please provide the entire picture of what you need to do so we can provide a fit soulition.
I don't see the necessity to use a variable if you run an ssh command. From what you showed in post #1, there is an entire directory listing to be processed, and you did not specify the output format desired.
Please provide the entire picture of what you need to do so we can provide a fit solution.
Ok. let me explain what exactly i want.
I'm using zenoss to monitor my servers. in the zenoss i cant handle the plain text. i just can use the numerical values. now i want create an alert to warn me if there was no back up files.
so i decided to wrote an script to do this.
now if you guys have better idea please share it with me.
i really appreciate any sort of help.
thank you.
Sorry, I can't imagine the picture from what you post. Wildly guessing: Do you need a script to be run on every server that checks all files and, if a full/level backup found within the last two days, sends a number (10/5) back? How do you intend to send the date parameter if you can handle numbers only? How do you want to store the script?
i was attempting to extract a directory path that was passed from a parameter with this code
vdir=`dirname $p1`
echo current directory $vdir
it does not work when the parameter passed has wild card on it.
for example
$ sh sample1.sh "/sbin/log/c*.log"
dirname: extra operand... (2 Replies)
Trying to download and extract a file to a specific folder, but getting an error. What am I doing wrong? Is there a way to rename the download if desired? Thank you :).
curl --url https://github.com/arq5x/bedtools2/releases/download/v2.26.0/bedtools-2.26.0.tar.gz | tar -xz --output... (4 Replies)
My input is as below :
/splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt
/splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt
/splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt
/splunk/scrubbed/triumph/ifind.triumph.txt
From the above input I want to extract the file names only .
Basically I want to... (5 Replies)
I think I know what this is doing, but the 'eval' is confusing
fname=$(echo ${lineItem} | awk 'BEGIN {FS=";"}{print $1}')
fname=${fname%%+(])}
fname=${fname##+(])}
eval "fname=${fname}"
The first line extracts the contents of the line preceeding the ";"
2nd & 3rd lines trim the value (I... (5 Replies)
I am trying to loop through folders and extract the name of the lowest level subfolder
I was running the script below, it returns
/bb/bin/prd/newyork
/bb/bin/prd/london
/bb/bin/prd/tokyo
I really want
newyork
london
tokyo
I couldn't find a standard variable for the lowest level... (1 Reply)
Im trying to extract a directory from a path entered by the user
Lets say the path is
path=/home/bliss/files/myfile.txt
i wanna extract "/home/bliss/files" from $path ... how can i do this? (4 Replies)
Hi,
I created a tar file of a directory dir1 from /tmp in the following way
$pwd
/tmp
$tar -cvf dir1.tar dir1 (dir1 will have say file1)
Now i want to extract it in the directory /tmp/dir2 so that the directory dir1 is also created and extracted... (1 Reply)
Hi,
I would like to extract the files from an archive which I have copied from a different server which has different file structures to my server.
When I do a tar xvf archive_name, I get the error saying the file or directory cannot be found. How do I specify a desginated directory to... (4 Replies)
anyone know if it is possable to extract a subdirectory in a tar file.
IE
tarfile contains
parent dir
-sub dir A
-sub dir B
I want to extract sub dir B. (2 Replies)
Is it possible to redirect the output from 'tar xvf' to another directory?
The taped tar image is extracting to my / dircetory - even though i'm running the command from /backups.
The contents list of the tape shows files created from /livebackups/...
Thanks
Richard (7 Replies)