LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-02-2009, 09:40 AM   #1
abharsair
LQ Newbie
 
Registered: Jan 2009
Posts: 17

Rep: Reputation: 0
Scripting problems (ARG!!!)


Hi guys, please can one of you help?

I've written a script (with some of your help ), that should scan a directory for files that end in the .dat suffix and then create a .dat.lck blank file with the same name as the .dat file.

Once this has happened the script then scans the directory for the .dat files and uses a pearl ftp script to send the files to a remote server.

Now my script work if there is only one file in the directory, however if there are more than one it says there are two many arguements, can you please tell me what I am doing wrong?

Thanks in advance guys

#!/bin/bash

MAILTO=email address

FTPSCRIPT=/usr/local/bin/autoftp.pl
LOGFTP=/var/log/autoftp.log
INCOMING=/shares/billops/test/out

function file_received()
{
local WHO=$1
local FILETO=$2

echo `date` $WHO": "$TOFILE >>$LOGFTP

mail -s "C&W Test Script - $WHO: $FILETO received" $MAILTO <<!
This message is for information only, please do not reply!
!
}

function send_file()
{
local status=1
local count=2
local WHO=$1
local FILEFROM=$2
local FILETO=$3
local DESTFTP=$4
local USER=$5
local PASS=$6

# Send mail informing file has arrived for onward FTP

file_received $WHO $FILETO

# Try 3 times to send file with 5 minute interval

while [ $status -gt 0 -a $count -gt 0 ]
do
/usr/bin/perl $FTPSCRIPT $DESTFTP $USER $PASS $FILEFROM $FILETO >>$LOGFTP 2>>$LOGFTP
status=$?
count=`expr $count - 1`

if [ $status -ne 0 ]
then
sleep 300
fi
done

# Report on status of sending file

if [ $status -eq 0 ]
then
MESSAGE="sent OK"
else
MESSAGE="send FAILED!"
fi
mail -s "Test Script - $WHO: $FILETO $MESSAGE" $MAILTO <<!
This message is for information only, please do not reply!
!
}

# this next section reads and filename that ends in .dat and creates a duplicate with the suffix .dat.lck

for file in /shares/billops/test/out/*.dat; do
touch "${file%.dat}.dat.lck"
done

# this should send the .dat file to the ftp destination.

if [ -f $INCOMING/*dat ]
then
chown nobody:nobody $INCOMING/*dat
send_file $INCOMING/*dat *dat "fqdn" host user password remotedir
fi

# this should sent the .lck file to the ftp destination.

if [ -f $INCOMING/*lck ]
then
chown nobody:nobody $INCOMING/*lck
send_file $INCOMING/*lck *lck "fqdn" host user password remotedir
fi
 
Old 02-02-2009, 10:04 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Code:
if [ -f $INCOMING/*dat ]
I think this is the wrong part, because when the wildcard is expanded the statement becomes
Code:
if [ -f /path/to/some/dir/file1.dat /path/to/some/dir/file2.dat /path/to/some/dir/file3.dat ]
but you cannot test for the existence of multiple files at once. Hence, a better way is to use a for loop over the .dat file, e.g. something like
Code:
for file in $INCOMING/*.dat
do
  chown nobody:nobody $file
  send_file $file $(basename $file) "fqdn" host user password remotedir
done

Last edited by colucix; 02-02-2009 at 10:06 AM.
 
  


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
ethernet and video problems! arg! remoh nospmis Linux - Hardware 4 04-12-2004 04:14 PM
problems with scripting in expect wedgeworth Linux - Software 1 10-07-2003 04:34 PM
Scripting Problems dolvmin Linux - Software 4 08-15-2003 01:33 AM
Gr arg newbie problems CBeske Slackware 2 02-02-2003 08:49 AM
scripting problems.. imnna2 Linux - Newbie 2 04-02-2001 10:44 AM


All times are GMT -5. The time now is 08:54 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration