Help/How-to - simple UNIX script / gzip (beginner)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help/How-to - simple UNIX script / gzip (beginner)
# 1  
Old 07-12-2012
Help/How-to - simple UNIX script / gzip (beginner)

Hey all,

I would like to ask your help and sorry in advance for my ignorance since I am a complete beginner in this.

I need to create a UNIX script that will:
- scan a small number of folders and subfolders (see a similar file tree in the attachment)
- [maybe in the future store some useful data to use for populating an XML file]
- for each final folder (each of them contain 6 files), compress the 6 files in .tgz
[it may also need to either read a version.txt file or identify filename_v2 and use it instead of filename_v1]

Any help or link to appropriate tutorial/link with examples would be greatly appreciated.

Thank you very much in advance.
Help/How-to - simple UNIX script / gzip (beginner)-examplejpg
# 2  
Old 07-12-2012
This is not clear to me. What are we "scanning" for?

Please give us a sample expected input and expected result
# 3  
Old 07-12-2012
The input would be a folder that contains always 6 files. For example the file Documents/Vol1/A/Filename_v1/
would contain:

filename_v1.gif
filename_v1.html
filename_v1.xls
filename_v1.txt
filename_v1.vsd
filename_v1.docx

The output would be those 6 files compressed into one .tgz named:

PR-2012MonthDayHour-XXXX-V1-XXXXXX-filename.tgz


I am sorry if I fail to explain it well. Thanks in advance.
# 4  
Old 07-12-2012
The attachment is hosed, cannot see it.
Code:
cd Documents/Vol1/A
find . -type d -exec basename  {} \; |
while read folder
do
   tar czvf /tmp/PR-2012`date +%m%d%H-XXXX-V1-XXXXXX-${folder}.tgz  $folder
done

This assumes that your version of tar supports the z options. It also assumes that when you cd to the directory: Documents/Vol1/A that you are in the directory immediately above Documents.

The compressed tar files end up in the /tmp directory.
# 5  
Old 07-12-2012
Thank you very, very much for the quick reply. I am currently on another computer, as soon as I test it I will come back to thank you again!
# 6  
Old 07-18-2012
There was an error message for "basename", not sure why (beginner)...

I received some more help and have this script:

Code:
#!/bin/sh
DST_DIR=/home/myname/Output/zipped
SRC_DIR=/home/myname/Input/Vol*/*
VERSION_FILE=version.txt
DT=`date +%Y%m%d%H`

for d in $SRC_DIR; do
        cd $d
        if [ -e $VERSION_FILE ]; then
                version=`cat $VERSION_FILE`
                if [ "$version" != "" ]; then
                        for f in `find . -path "*_v${version}"`; do
                                dirpath=`echo $d | rev | cut -d / -f1,2 | rev | sed 's/\//-/'`
                                cleanname=`echo $f | cut -d / -f 2 | cut -d _ -f 1`

                                tar zcvfp $DST_DIR/Proc_Sat-1-${DT}-S515-V${version}-OUNCL-P${dirpath}-${cleanname}.tgz $f > /dev/null 2>&1
                                if [ $? -ne 0 ]; then
                                        echo "error in backup" # add better error handling here
                                fi
                        done
                fi
        fi
done

# tar zcvfp Proc_Sat-1-${DT}-S515-V${version}-OUNCL.tar.gz Output/total

any ideas why it doesn't zip the files? It reads the folders and I receive no error message.

Thanks in advance!
# 7  
Old 07-18-2012
Could you post the Operating System and version you are using. Many systems give you this output from the command
Code:
uname -a

....but yours may not. Feel free to obscure sections showing your host name/ipaddress or anything else that shows up that you wouldn't want to publish.




Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help on simple script as i dont know numch about UNIX scripting

Hello All, My name is vasu and I am very new to Unix scripting, i know basic commands, but now i need to write the following script, i have tried but no luck My requirment is i am getting one our from another command as following Used:1.8TB Advisory Quota:1.8TB aaa1 Used:4.5TB Advisory... (1 Reply)
Discussion started by: VasuKukkapalli
1 Replies

2. Shell Programming and Scripting

need a script that does a simple task on multiple unix servers.

hi guys, i need a script that does a simple task on multiple aix servers. if possible with both telnet and ssh. the simple task i wanna do is connect to a server and run "ifconfig -a" and get the output. nextweek i need to do similar jobs on like 50 servers... :( can anybody help me with making... (2 Replies)
Discussion started by: curtis911
2 Replies

3. Shell Programming and Scripting

Cannot execute Unix command in a simple perl script

Am trying to lean perl scripting in Unix OS to automate my tasks. Please find the below perl script i have tried #!/usr/bin/perl -w print "Please Enter the VG name to be checked:"; $A = <>; print "Please Enter the free size to be checked in GB:"; $B = <>; $vgcheck = `vgdisplay... (7 Replies)
Discussion started by: jayachandran87
7 Replies

4. Shell Programming and Scripting

very simple but mount everest for beginner

List directories at the home directory in increasing order. First of all is this correct? cd ~/ du -h|sort -n|more First command is to go to the home directory and second does the rest. Is there a way to do them in single command. Thanks in advance. (1 Reply)
Discussion started by: kevincobain2000
1 Replies

5. Shell Programming and Scripting

Help with simple program. (beginner)

Hey all, Writing a program that searches for a username and if they are online creates a 'beep' and sends the username and date to a log file. the error i am getting is: paul.obrien16@aisling:~/os$ bash checklogin : command not found Enter username paul.obrien16 ': not a valid... (2 Replies)
Discussion started by: sexyladywall
2 Replies

6. Shell Programming and Scripting

Simple unix variables in script

I'm creating a script that asks a user for a variable ex read filename; read numberinput; I also have a bunch of files named file.0 file.1 ... file.55 I'm trying to delete all files (if they exist) about file.$numberinput. Can someone help me out on how to include the variable as part... (6 Replies)
Discussion started by: jenix4545
6 Replies

7. Shell Programming and Scripting

A simple query on unix shell script

I want to write a script to go to particular path in file and run shell script from there. what will be shell script for the same. (2 Replies)
Discussion started by: shekhar_ssm
2 Replies

8. UNIX for Dummies Questions & Answers

A beginner for cygwin simple question

the current pwd is: c:\cygwin\home\hui which command can go to c:\documents and setting\hui\my documents\hui\reply.txt (1 Reply)
Discussion started by: zhshqzyc
1 Replies

9. Shell Programming and Scripting

simple unix script help

when i run this script: # Author: xtos if then echo "Please enter ONLY one name to search, (example "$0" NAME)" exit fi INPUT="grep $1 $HOME/work/phone_book" if then echo "Listing not found, please try again." else (2 Replies)
Discussion started by: xtos
2 Replies

10. UNIX for Dummies Questions & Answers

Simple UNIX Shell Script help, PLEASE

I don't know anything about UNIX. I have been developing on NT platform and now a batch file I was running in my java code must work on UNIX instead. How do I change the below .bat file into a shell script that can be run on UNIX? Thanks in advance for your help. @ECHO OFF D:... (1 Reply)
Discussion started by: ci2a020
1 Replies
Login or Register to Ask a Question