Sponsored Content
Top Forums Shell Programming and Scripting Take action if a particular file appears in a directory Post 302324453 by mrudula009 on Wednesday 10th of June 2009 07:37:04 PM
Old 06-10-2009
Quote:
Originally Posted by KevinADC
Well, it is your task, so what have you tried?
THis is my file named mycron which I add it to the crontab entry later to run every 5 mins and this works. But I havnt done the last part - to run another script if everything succeeds.

Thanks for the reply Yogesh. But in ur code, what if the mv fails - ie, say the destination directory doesnt exist or something else ... only after all this succeeds I need to start another script.

#
# Taking action if a particular file appears in a dir
#

filename="/home/mrudula/myfile"

count=`find "$filename" | wc -l`

if [ "$count" -eq 1 ]
then

# Renaming filename
new_filename="$filename".new
mv $filename $new_filename
echo "$filename" renamed to "$new_filename"

# Moving to backup directory

bkup_dir="$filename"-bckup
mkdir "$bkup_dir"
mv "$new_filename" "$bkup_dir/$(basename $new_filename)"
echo "$new_filename" moved to "$bkup_dir"
else
echo "No file found - "$filename""
fi
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 different file version and prompt for action

Hi, I need some assistance with comparing 2 diff application. The format of the first file is in TAR "filename.1.2.3.tar" . The second file is a running application for which i need to find the version and then prompt the user for action as below :- Once compared, It needs to prompt the user,... (0 Replies)
Discussion started by: systemali
0 Replies

2. Shell Programming and Scripting

Clean file in single action

What one finds challenging another finds simple... (HPUX B.11.11) I have a text file named something like 12345.dst that could look like this: DOG CAT NONE TEST CAT What I want to end up with is 12345.dst looking like this: CAT DOG TEST removing "NONE" should it be there and... (1 Reply)
Discussion started by: djp
1 Replies

3. Shell Programming and Scripting

Perform action file name written to the pipe

Hello, I have a script that monitors files uploaded via ftp. After a successful upload, the file name is written to the pipe. There is another program that reads this pipe and allows automatically run any program or script ( say test.sh ) to process the newly uploaded file. cat test.sh... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies

4. Shell Programming and Scripting

grep'ing a file until a certain message appears

Hello, I'm writing a script that will automate the launch of some services on my AIX machine. However, some services are dependent on the successful startup of others. When I start these services manually, I usually just check a log file until I see a message that confirms a successful... (3 Replies)
Discussion started by: pallak7
3 Replies

5. Shell Programming and Scripting

Opening file and executing an action

I want the script to read the directory I am running the script from and print the contents of any file that has GX in it's title. This is the code needed. But how do I combine it? #!/usr/bin/perl opendir(CURRENT,"."); @list = readdir(CURRENT); closedir(CURRENT); foreach $item (@list){... (4 Replies)
Discussion started by: DemonixX
4 Replies

6. Shell Programming and Scripting

Take action only if a file is X hours (or seconds) old

shell: #!/bin/ash I searched and found a few relevant posts (here and here - both by porter, on the same day (?)) however both are just a do while loop, I need to check a file date and compare it to the current time. I would like it to say if file 'test' is more than 12 hours old than "right... (3 Replies)
Discussion started by: phdeez
3 Replies

7. UNIX for Dummies Questions & Answers

how to find a word in a file that appears next to a given keyword

Hi Experts, I have a file which contains some text. i need to print the word next to a given keyword. Please help. Ex: test.txt ===================== NEXT HOST ===================== AEADBAS001 access-list 1 permit xxxxxxxxxxxxxx ip access-list extended BLA_Outgoing_Filter... (6 Replies)
Discussion started by: mwrg
6 Replies

8. Shell Programming and Scripting

Shell program to check if the same text appears twice in an XML file

Hi All, I am very new to this forum and beginner to shell scripting. I need a shell script to: Search for a text in XML file à if the same text appears twice in an XML file à output file name Script should loop thru every xml file of a given folder. Please help me writing this script. ... (1 Reply)
Discussion started by: amardeep001
1 Replies

9. Shell Programming and Scripting

Read all lines after a string appears in the file.

Hi All, I want to read all lines after a perticular string {SET UP VALUES}apprears in the file. SET UP values contains direcory, number of days and file type. Step1: Read all lines below SET UP VALUES string. Step2: If set up values are not present in each record then read from default... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies

10. UNIX for Beginners Questions & Answers

Compare file name and take action

Have some files in /tmp/dir abc.zip 123.zip 345.zip and if name matches to 345.zip then take action My code.... am i doing something wrong ? Please advise. #!/bin/bash set -x cd /tmp/dir for i in *.* do if ] then (4 Replies)
Discussion started by: abhaydas
4 Replies
ConfigFile(3pm) 					  LogReport's Lire Documentation					   ConfigFile(3pm)

NAME
Lire::Config::ConfigFile - Class for configuration file manipulation. SYNOPSIS
use Lire::Config::ConfigFile; DESCRIPTION
Object representing a Lire configuration file. new( 'filename' => $file, spec => $config_spec ) Creates a new Lire::Config::ConfigFile object. The constructor takes two parameters: filename The file form where the configuration was stored or was loaded from. spec The Lire::Config::TypeSpec object to which this configuration adheres. filename( [$new_filename] ) Returns (and optionally changes) the filename where this configuration file should be stored. spec() Returns the Lire::Config::TypeSpec object to which this configuration file adheres. global( [ $config] ) Returns or modify the 'global' configuration part of the file. This is an instance Lire::Config::Compound object. save() Saves this ConfigConfigFile object back to the filename from which it was loaded. revert() Reads back the configuration from the file. as_value() Returns this configuration file as an hash reference. Delegates to the global configuration object contained in the file. get( $name ) Returns the configuration parameter $name from this configuration file. Delegates to the global configuration object contained in the file. is_set( $name ) Checks that a configuration parameter is set in this file. Delegates to the global configuration object contained in the file. set( $param ) Sets a configuration variable in the file. Delegates to the global configuration object contained in the file. SEE ALSO
Lire::Config::Dictionary(3pm) AUTHORS
Wessel Dankers <wsl@logreport.org> Francis J. Lacoste <flacoste@logreport.org> Wolfgang Sourdeau <wolfgang@logreport.org> VERSION
$Id: ConfigFile.pm,v 1.9 2006/07/23 13:16:30 vanbaal Exp $ COPYRIGHT
Copyright (C) 2002-2004 Stichting LogReport Foundation LogReport@LogReport.org This file is part of Lire. Lire is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (see COPYING); if not, check with http://www.gnu.org/copyleft/gpl.html. POD ERRORS
Hey! The above document had some coding errors, which are explained below: Around line 42: '=end' without a target? Around line 64: You forgot a '=back' before '=head2' Lire 2.1.1 2006-07-23 ConfigFile(3pm)
All times are GMT -4. The time now is 09:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy