Extract directory name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract directory name
# 15  
Old 02-02-2015
Quote:
Originally Posted by RudiC
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?
ye exactly.
i don't want to send any date parameters. just a simple yes or no is enough for now.
the script store in my zenoss server and run via ssh(with pki and without password authentication.)
Thank you.
# 16  
Old 02-02-2015
Does this - executed on your servers, assuming you run a recent bash shell - yield what you need:
Code:
ls @(full|level)*$(date +%Y%m%d -d-1day)* | { read FN; case "$FN" in full*) echo 10;; level*) echo 5;; *) echo 0;; esac; }

?
This User Gave Thanks to RudiC For This Post:
# 17  
Old 02-03-2015
Quote:
Originally Posted by RudiC
Does this - executed on your servers, assuming you run a recent bash shell - yield what you need:
Code:
ls @(full|level)*$(date +%Y%m%d -d-1day)* | { read FN; case "$FN" in full*) echo 10;; level*) echo 5;; *) echo 0;; esac; }

?
thank you.
result:
Code:
-bash: syntax error near unexpected token `('

# 18  
Old 02-03-2015
Sorry, failed to mention you need to set the extglob option: shopt -s extglob.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Extract directory path from a parameter

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)
Discussion started by: wtolentino
2 Replies

2. Shell Programming and Scripting

Download and extract to a specific directory

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)
Discussion started by: cmccabe
4 Replies

3. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

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)
Discussion started by: IshuGupta
5 Replies

4. UNIX for Dummies Questions & Answers

Extract directory from full file name?

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)
Discussion started by: jdorn001
5 Replies

5. UNIX for Dummies Questions & Answers

Loop through directory and extract sub directory names

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)
Discussion started by: personalt
1 Replies

6. Shell Programming and Scripting

Extract directory from a file path

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)
Discussion started by: mrudula009
4 Replies

7. UNIX for Advanced & Expert Users

tar extract to different directory

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)
Discussion started by: ammu
1 Replies

8. UNIX for Dummies Questions & Answers

How to extract archive to a specified directory

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)
Discussion started by: john_trinh
4 Replies

9. UNIX for Advanced & Expert Users

extract a sub directory form a tar file

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)
Discussion started by: Optimus_P
2 Replies

10. UNIX for Dummies Questions & Answers

redirecting tar extract to another directory

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)
Discussion started by: colesy
7 Replies
Login or Register to Ask a Question