LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-25-2008, 06:36 PM   #1
nazs
Member
 
Registered: Apr 2005
Posts: 57

Rep: Reputation: 15
Scripting question


Hi All,
I have a script that looks for a file. Then changes the name of the file and then scp's it to another server. The problem is this was set up for one file to be in the directory. Now there is going to be another file with the same name but different information in it. I need to add a way to check inside the file and look on the first line of the file for a sequence of numbers(ex. 123456789). If that file has the sequence of numbers then finish the rest of the script.If it does not match the sequence then exit the script. My existing script is below.


#!/bin/sh -x

pospay=/usr/pa/archive/bw/bin_wsobserve/pospay

archive=/usr/pa/archive/bw/bin_wsobserve/pospay/archive

dest=/usr/pa/archive/bw/bin_wsobserve/pospay/wsobserve

sent=/usr/pa/archive/bw/bin_wsobserve/pospay/wsobserve/sent

cd "$pospay"

#CHECK IF THERE ARE ANY POSITIVE PAY FILES
if [ `find . -type f -maxdepth 1 -name "1455*" | wc -l` -eq 0 ]; then
echo "Exit NO FILES"
exit
else

gunzip 1455*

for file in 1455*
do
#this copies the file to new directory and removes everything after the -

cp "$file" "$dest/${file%%-*}"

gzip 1455*

mv "$pospay"/*.gz "$archive"

cd "$dest"

scp 1455* abcd@xfer.abcd.com:/usr/pa/warner/wbdumpdir/bin_wsobserve

gzip "$dest"/1455*

mv "$dest"/1455* "$sent"

slogin abcd@xfer.abcd.com "cd /usr/pa/warner/wbdumpdir/bin_wsobserve" "touch cur_dump.wsobserve;echo "1455"* >> cur_dump.wsobserve
;/usr/local/bin/bwconcord_send_wsobserve"

done
fi

Thanks,
Nazs
 
Old 04-25-2008, 07:11 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,336

Rep: Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548Reputation: 548
Quote:
Originally Posted by nazs View Post
Hi All,

The problem is this was set up for one file to be in the directory. Now there is going to be another file with the same name but different information in it.
How can you have two files with the same name in the same directory?

--------------------------
Steve Stites
 
Old 04-25-2008, 07:47 PM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
The first file by the same name will probably be overwritten when the second file is saved. It may be possible if it was created by something that directly manipulates the file system or if the file system becomes currupted. In that case you will need to list the inodes of the file and use the find command to select the file by the inode. The "ls -i" command will list the inode as well as the filename. Using something like "find . -inum 7159974 -exec mv -v '{}' temp/'{}' \;" will allow you to move one of the duplicates out of the way.

However, having two files in the same directory with identical names is something that needs to be prevented. Either add a time stamp or other meaningful pattern to the filename or create them in separate directories whose names are based on some criteria.
 
Old 04-26-2008, 02:25 PM   #4
nazs
Member
 
Registered: Apr 2005
Posts: 57

Original Poster
Rep: Reputation: 15
I am sorry. Let me clarify the same name question. Both files start with 1455.LOC. The program that we use creates this file name and then adds a random ending to it. Example file would look like this 1455.LOC-30421-7787E443609E138318DFFC27C14E80A6.gz
So everything after the dash is random. That way the file does not get over written. But there is no way to tell what will be added on after the dash.

Thanks,
Nazs
 
Old 04-27-2008, 12:48 AM   #5
angrybanana
Member
 
Registered: Oct 2003
Distribution: Archlinux
Posts: 147

Rep: Reputation: 21
Do you mean something like this?
Code:
if [[ $(head -1 file) == 123456789 ]];then
    echo "do stuff"
else
    exit
fi
another way of doing the same..
Code:
read line < file
if [[ $line == 123456789 ]];then
    echo "do stuff"
else
    exit
fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting question jim.thornton Linux - Newbie 10 03-24-2008 08:12 AM
Scripting question msandford Linux - Newbie 4 09-05-2005 10:23 AM
Question about scripting RitzContent Programming 18 11-23-2004 10:34 AM
Scripting Question caps_phisto Linux - General 1 11-05-2004 02:43 PM
scripting question gearoid Programming 3 05-26-2004 02:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration