The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to launch Eclipse in Solaris 10 wilsontan UNIX for Dummies Questions & Answers 5 02-26-2009 03:44 PM
How to launch a new process hr94131 High Level Programming 5 05-05-2008 05:34 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 06:06 PM
launch an executable from a C++ program nadiamihu High Level Programming 2 11-03-2006 05:59 AM
How do you launch an .exe from my app? kapolani High Level Programming 1 01-03-2005 06:00 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-12-2007
Minguccio75 Minguccio75 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 33
launch a command only if

Hi!
I would launch this command:

tar -cvvf logswitch.tar `find *.log* -mtime +5` --remove-files

only if

find *.log* -mtime +5

find some files.

Thanks in advance.
  #2 (permalink)  
Old 02-12-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
tar -cvvf logswitch.tar `find . -type f -name \*.log\* -mtime +5` --remove-files

Assuming the fles are in or below the directory . (current dir)
  #3 (permalink)  
Old 02-13-2007
Minguccio75 Minguccio75 is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 33
Thanks I'll try.
  #4 (permalink)  
Old 02-13-2007
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Code:
FILES=$(find *.log* -mtime +5)
if [[ "$FILES"  != "" ]]; then tar -cvvf logswitch.tar $FILES --remove-files; else echo NO FILES FOUND; fi
  #5 (permalink)  
Old 02-13-2007
moshe fried moshe fried is offline
Registered User
  
 

Join Date: Feb 2007
Location: Israel
Posts: 24
running command on condition

I assume you don't want the file to be created if no files are given.
$(FILES)=$(find .....)
[[ -z $FILES ]] || tar ... $(FILES)
  #6 (permalink)  
Old 02-13-2007
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Quote:
Originally Posted by moshe fried
I assume you don't want the file to be created if no files are given.
$(FILES)=$(find .....)
[[ -z $FILES ]] || tar ... $(FILES)
mmmm... Good one.
The syntax is not correct though, at least for ksh/bash... It should read:
Code:
FILES=$(find .....)
[[ -z "$FILES" ]] || tar ... $FILES
Regards.

Last edited by grial; 02-13-2007 at 06:37 AM.. Reason: I'm a clumsy guy today :)
  #7 (permalink)  
Old 02-13-2007
moshe fried moshe fried is offline
Registered User
  
 

Join Date: Feb 2007
Location: Israel
Posts: 24
Thanx!
Whoops sorry, my perl background is showing:-)
Sponsored Links
Closed Thread

Bookmarks

Tags
mtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0