launch a command only if


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users launch a command only if
# 1  
Old 02-12-2007
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  
Old 02-12-2007
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  
Old 02-13-2007
Thanks I'll try.
# 4  
Old 02-13-2007
Code:
FILES=$(find *.log* -mtime +5)
if [[ "$FILES"  != "" ]]; then tar -cvvf logswitch.tar $FILES --remove-files; else echo NO FILES FOUND; fi

# 5  
Old 02-13-2007
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  
Old 02-13-2007
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  
Old 02-13-2007
Thanx!
Whoops sorry, my perl background is showing:-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Not able to see the terminal icon in the applications menu to launch the command prompt in Centos

After installing centos iam not able to see the terminal icon in the applications menu to launch the command prompt in Centos. However iam able to see the Open Terminal menu, when i right click and it is not working. let me know what are the things i need to check.:b: (1 Reply)
Discussion started by: Kesavan
1 Replies

2. Shell Programming and Scripting

How do I launch a command on an existing terminal in unix using PERL

Hello, I have a PERL-TK based GUI from which I want to launch a command on an existing UNIX terminal (this is also the parent terminal for this perl based gui window). The command I want to launch is interactive (there is no intention to interact with that command from the same PERL gui i.e. no... (2 Replies)
Discussion started by: AnuragJindal
2 Replies

3. OS X (Apple)

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In the... (2 Replies)
Discussion started by: JFraser1
2 Replies

4. Shell Programming and Scripting

Need help writing an Applescript to launch a specific Terminal Command...

I developed a script in Lingon (which is an automated script editor developed for OS X) that is used to automatically restart programs only if they crash. The script itself does just that, but I only want it to load if I'm going to use the specific application that it's designed to protect. In... (3 Replies)
Discussion started by: JFraser1
3 Replies

5. Shell Programming and Scripting

Launch Script

Hi all! I just got done writing a script. The problem Im running into is I have to lanuch the script with: sh SCRIPT.sh Is there a way to launch it with by just entering SCIPT into the shell? (3 Replies)
Discussion started by: Grizzly
3 Replies

6. Linux

Can't launch firefox

Hi all, I installed RHEL on my machine and realized that firefox browser was not included at installation. I went back and added it using the Add or Remove Packages by inserting the dvd I used during installation. The icon is there but for some reason I cannot lauch. Nothing returns when I... (12 Replies)
Discussion started by: jxh461
12 Replies

7. Programming

How to launch a new process

Hi, I have a situation where a C main program needs to call another C main program, my background is mostly Windows and I'm new to UNIX programming. I've read about system(), fork(), and exec() and I'm a little confused as to what the sequence of steps should be to launch another process. By the... (5 Replies)
Discussion started by: hr94131
5 Replies

8. Shell Programming and Scripting

how to? launch command with string of command line options

my description from another thread... here's my code: #!/bin/bash IFS=$'\n' function OutputName() { input=$1 echo $input input=`echo "$input" | sed -e 's/.//'` input=`echo "$input".avi` output_name=$input } if ]; then echo... (5 Replies)
Discussion started by: TinCanFury
5 Replies

9. Solaris

Eclipse launch question

I just bought my first Ultra 20 (Solaris 10) and I would like to know the step by step directions to launch eclipse please. I have unzipped the eclipse folder in my temp directory I am having really hard time launching eclipse from my desktop. (7 Replies)
Discussion started by: saif
7 Replies

10. UNIX for Dummies Questions & Answers

how to launch program though telnet

I have launched telnet on nt and have connected to a unix server, I'm trying to run a program on the unix server which will launch a gui, but when I try to launch it I get the message "display not set\n" "By default set it to 0.0" I can sit down at the unix machine and launch the program with... (3 Replies)
Discussion started by: cbachman
3 Replies
Login or Register to Ask a Question