Sponsored Content
Top Forums Shell Programming and Scripting shell script - search a file and perform some action Post 302451826 by zaxxon on Wednesday 8th of September 2010 06:48:25 AM
Old 09-08-2010
The script could look like:
Code:
#!/bin/bash

FILENAME=service.tra
S_PATH=/path/to/your/trace
D_PATH=/home/linus/gaurav

while :; do
   FOUND=$(find $S_PATH -type f -name "$FILENAME" -size +3000c -print)
   if [[ -n $FOUND ]]; then
      echo "File $FILENAME is larger than 3k - moving it."
      mv $FOUND $D_PATH
   fi
   sleep 3
done

exit 0

For infinite loops maybe put a sleep in there - else it might push your box to 100% CPU usage. In this example I use "find" but when the destination of the mv is also below this path, you'll get a problem, just as a site note. You might to use -purge in the find or check with ls -l or stat for the size of the file instead and check with -e if the file exists before that.

Code:
$one=`expr $one + 1`

Will not work since in a shell script there may be no spaces on the left or right of the equal sign. Also when declaring a variable there may be no $ in the name of the variable.
 

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Need help in searching 2 files for strings then perform an action

I have 2 files. I basically want to search both of them to see if the 1st column ($1) matches and if it matches then check to see if the 2nd column ($2) matches, then execute some code showing the results of the matches. File 1: AAA 123 misc blah BBB 456 CCC 789 File 2: ... (2 Replies)
Discussion started by: streetfighter2
2 Replies

3. Shell Programming and Scripting

How to perform action on newest line in log using tail?

I don't quite know what I'm doing, so this simple script is proving a challenge. Here is some pseudo code that doesn't work yet: if tail -1 "WORKING.txt" >/dev/null | egrep "^NMBR=*" > /dev/null then curl -k 'http://www.myserver.com/log.cgi?input=$?' echo "hi there" fi Purpose:... (3 Replies)
Discussion started by: dihewidd
3 Replies

4. Shell Programming and Scripting

create dir in main &subdirs,perform action

Hi, I have one dir which has N subdirs.For ex: /home/user/Project_Src /home/user/Project_Src/Dir_A /home/user/Project_Src/Dir_A/subdir/sub_dir2 /home/user/Project_Src/Dir_A/subdir/sub_dir3 /home/user/Project_Src/Dir_B /home/user/Project_Src/Dir_B/Build i want to create a folder with... (2 Replies)
Discussion started by: dragon.1431
2 Replies

5. Shell Programming and Scripting

How to access files from different directories and to perform search action in those files?

Hi, I want to access files from different directories (for example: /home/dir1/file1 , /home/dir2/file2 ...) Like this i have to access these files(file1, file2...). (3 Replies)
Discussion started by: bangarukannan
3 Replies

6. Shell Programming and Scripting

Script to monitor for new file with ext .err and size > 0 bytes and perform a action or command

Hi All, I need to create a script to monitor a dir for new files with ext .err and also it should b a non empty files. and perform a action or command . We have a new ETL application that runs on a linux server, every times a etl fails it creates a .err file or updates the existing .err... (4 Replies)
Discussion started by: MAKHAN
4 Replies

7. Homework & Coursework Questions

Shell Script to read a tab delimited file and perform simple tasks

1. The problem statement, all variables and given/known data: Hello! I need help with this problem bash shell scripting that basically just reads the data in a tab delimited file and does the following below 1. Read in the data file Survey.txt and assign the column values to variables of... (6 Replies)
Discussion started by: jsmith6932
6 Replies

8. Shell Programming and Scripting

Perform an action if certain text exist in output (PERL)

Hello, I'm attempting to write a tool that checks an IP address for existing PTR records then if there are no PTR records does a ping to see if it response. Then if there is no response, it should print a message saying This is what I have so far. #!/usr/bin/perl $nxdomain =... (4 Replies)
Discussion started by: spartan22
4 Replies

9. Shell Programming and Scripting

awk script to perform an action similar to vlookup between two csv files in UNIX

Hi, I am new to awk/unix and am trying to put together an awk script to perform an action similar to vlookup between the two csv files. Here are the contents of the two files: File 1: Date,ParentID,Number,Area,Volume,Dimensions 2014-01-01,ABC,247,83430.33,857.84,8110.76... (9 Replies)
Discussion started by: Prit Siv
9 Replies
SURFRAW-UPDATE-PATH(1)					User Contributed Perl Documentation				    SURFRAW-UPDATE-PATH(1)

NAME
surfraw-update-path - updates PATH in shell config files SYNOPSIS
surfraw-update-path [-add] [-remove] [-check] [-sys] [-all] [-help] [-shell=SHELL] DESCRIPTION
surfraw-update-path adds the surfraw elvi directory (/usr/lib/surfraw) to your PATH in your shell's config file. Currently it supports bash, sh, csh, tcsh, ash, dash, ksh, pdksh, zsh, rc, and es Don't forget to login again or source your login files for it to take effect. OPTIONS
-check Checks to see if the surfraw config code is present. This is the default. -add Adds the surfraw config code. -remove Removes the surfraw config code -sys Updates the system-wide shell config instead of the user. Must be done as root. -shell=SHELL Selects the shell to configure. Defaults to the value of the $SHELL environment variable. Currently supported shells are: sh, ash, bash, dash, csh, tcsh, ksh, pdksh, zsh, rc, and es. -all Attempts to configure the startup files for all known shells -help Gives a usage message RETURN VALUE
-check returns 0 if the surfraw code is present in the file, 1 if it is not found, or 2 on error. All other options return 0 on success, or 2 on error. ENVIRONMENT
SHELL Used to determine which shell to configure, if -shell is not given. HOME Used to find users config files. ENV Used by posix-compliant shells to specify a startup rc file. ZDOTDIR Used to find user config files for zsh. If not set, defaults to HOME. SEE ALSO
surfraw(1), sh(1), ash(1), bash(1), dash(1), csh(1), tcsh(1), ksh(1), pdksh(1), zsh(1), rc(1), es(1) AUTHOR
Ian Beckwith <ianb@erislabs.net> perl v5.12.4 2011-07-12 SURFRAW-UPDATE-PATH(1)
All times are GMT -4. The time now is 09:50 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy