- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: help with a script to gzip/move files
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
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
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
тАО08-10-2011 11:39 PM
тАО08-10-2011 11:39 PM
Hi
I need help on a script that runs through a dir (not recursvely) gzip files based on month, them send these gziped files to a subdir in the same directory.
Your help will be appreciated
Nandinho
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2011 04:27 AM
тАО08-11-2011 04:27 AM
Re: help with a script to gzip/move files
>runs through a dir (not recursively) gzip files based on month
Month of modification or encoded in the filenames?
>them send these gzipped files to a subdir in the same directory.
Something like:
#!/usr/bin/ksh #runs through a dir (not recursively) gzip files based on month #them send these gzipped files to a subdir in the same directory. if [ $# -ne 1 ]; then echo "Usage: $0 month-to-backup" 1>&2 exit 1 fi \ll -og | awk -v month=$1 '$4 == month { print $7 }' | while read file; do echo gzip $file echo mv $file.gz Subdir done
Remove the echo if this matches what you want to do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2011 05:13 AM
тАО08-11-2011 05:13 AM
Re: help with a script to gzip/move files
Hi
Thanks a lot, but please if its is not asking too much is it possible to put some comments on each line for better understanding of the script?
Nandinho
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2011 05:55 AM
тАО08-11-2011 05:55 AM
Solution> is it possible to put some comments on each line
#!/usr/bin/ksh #runs through a dir (not recursively) gzip files based on month #them send these gzipped files to a subdir in the same directory. if [ $# -ne 1 ]; then # make sure only one parm echo "Usage: $0 month-to-backup" 1>&2 exit 1 fi SUBDIR=Subdir # Set subdirectory name MONTH=$1 # month parm \ll -og | # list files in current directory, leaving out owner/group awk -v month=$MONTH ' # use -v to pass shell variable to awk variable $4 == month { print $7 }' | # select files (field 7) with month (field 4) while read file; do # for each file that matches month ($1) echo gzip $file # gzip echo mv $file.gz $SUBDIR # move to $SUBDIR directory done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2011 06:00 AM
тАО08-11-2011 06:00 AM
Re: help with a script to gzip/move files
@Nandinho wrote:Thanks a lot, but please if its is not asking too much is it possible to put some comments on each line for better understanding of the script?
Dennis provided more than "help". He wrote a simple, straight-forward script to solve your problem.
You will be better served if *you* consult the manpages for the commands he used and try to understand what each piece of the script does. You may need to begin by reading a beginner's guide to shell scripting if you don't have a good grasp of the basics.
If there is a specific line or two of the script that you are struggling over then ask about that after you have made some attempt to understand it. My comments are not intended to dismiss your question but rather to help you grow.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2011 06:23 AM
тАО08-11-2011 06:23 AM
Re: help with a script to gzip/move files
Hi James!
Thanks a lot for your inputs, and advise, I will be doing that
Nandinho
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-11-2011 11:48 PM
тАО08-11-2011 11:48 PM
Re: help with a script to gzip/move files
I have the following script:
touch -mt 201108010000 /tmp/ref1
touch -mt 201108012359 /tmp/ref2
find /somedir -type f \( -newer /tmp/ref1 -a ! -newer /tmp/ref2 \)> file_list
scp -p $(< file_list) root@10.100.48.11:/another_dir/
How do I count the number of files sent, and get this number and send it to an email address?
Nandinho
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2011 01:09 AM
тАО08-12-2011 01:09 AM
Re: help with a script to gzip/move files
>How do I count the number of files sent, and get this number and send it to an email address?
echo "Files sent: $(wc -l < file_list)" | mailx -s "Files transferred" abc@def.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-12-2011 03:01 AM
тАО08-12-2011 03:01 AM
Re: help with a script to gzip/move files
Thank you, worked fine.
Nandinho