LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   invalid command (http://www.linuxquestions.org/questions/programming-9/invalid-command-698809/)

vodka33us 01-21-2009 05:23 AM

invalid command
 
can anyone help me? i try to make an autoscript for send the log file to my windows. i want to make this file run every 15 minutes. so i make file time_sch.txt
this is my autoscript file
Code:

#/bin/bash
NAME=$(hostname)
TIME=$(date +%d%m%Y%H%M)

cat /var/log/httpd/access_log > http$NAME$TIME.txt
cat /var/log/vsftpd.log > ftp$NAME$TIME.txt
mysqladmin --host='localhost' --password='mysql' extended-status > dbase$NAME$TIME.txt
ifconfig >> serverinfo$NAME$TIME.txt

HOST='192.168.0.5'
USER='vodka33us'
PASS='conan33'
ftp -i -n -u $HOST << root
user ${USER} ${PASS}

binary


put http$NAME$TIME.txt
put ftp$NAME$TIME.txt
put dbase$NAME$TIME.txt
put serverinfo$NAME$TIME.txt

quit
root


rm http$NAME$TIME.txt
rm ftp$NAME$TIME.txt
rm dbase$NAME$TIME.txt
rm serverinfo$NAME$TIME.txt

SCH=$(cat /root/time_sch.txt)

if [ ! -f STOPFILE ]
then
  at -f autoscript now +$SCH minutes
fi


acid_kewpie 01-21-2009 05:28 AM

??? of course we can't... how can we know what the issue is if we can't see the script??

vodka33us 01-22-2009 02:20 AM

can anyone help me? i try to make an autoscript for send the log file to my windows. i want to make this file run every 15 minutes. so i make file time_sch.txt
this is my autoscript file
Code:

#/bin/bash
NAME=$(hostname)
TIME=$(date +%d%m%Y%H%M)

cat /var/log/httpd/access_log > http$NAME$TIME.txt
cat /var/log/vsftpd.log > ftp$NAME$TIME.txt
mysqladmin --host='localhost' --password='mysql' extended-status > dbase$NAME$TIME.txt
ifconfig >> serverinfo$NAME$TIME.txt

HOST='192.168.0.5'
USER='vodka33us'
PASS='conan33'
ftp -i -n -u $HOST << root
user ${USER} ${PASS}

binary


put http$NAME$TIME.txt
put ftp$NAME$TIME.txt
put dbase$NAME$TIME.txt
put serverinfo$NAME$TIME.txt

quit
root


rm http$NAME$TIME.txt
rm ftp$NAME$TIME.txt
rm dbase$NAME$TIME.txt
rm serverinfo$NAME$TIME.txt

SCH=$(cat /root/time_sch.txt)

if [ ! -f STOPFILE ]
then
  at -f autoscript now +$SCH minutes
fi

and then
Code:

[root@fedora ~]# chmod 755 autoscript
[root@fedora ~]# ./autoscript
?Invalid command
?Invalid command
?Invalid command
/httpfedora.net.id190120092001.txt: Cannot create file.
: No such file or directory
/dbasefedora.net.id190120092001.txt: Cannot create file.
/serverinfofedora.net.id190120092001.txt: Cannot create file.
?Invalid command
?Invalid command
: command not found25:
rm: cannot remove `ftpfedora.net.id\r190120092001.txt\r': No such file or directory
: command not found31:
: command not found33:
: command not found34:
./autoscript: line 39: syntax error: unexpected end of file

i try this one
Code:

[root@fedora ~]# bash ./autoscript
bin bash^m bad interpreter


acid_kewpie 01-22-2009 02:39 AM

gah, don't edit the original thread... how confusing is that?

chrism01 01-22-2009 06:02 AM

The first line defines the interpreter incorrectly, you need

Code:

#!/bin/bash
Note the exclamation mark

Also, it looks like you're trying to write to the root dir (of the disk, not root user's home dir).
/httpfedora.net.id190120092001.txt: Cannot create file.

You need to be careful where you run it from, or specify the path to write to (latter preferred for when its in cron, later)

When using embedded vars in a value, I recommend using extra parentheses

http$NAME$TIME.txt

becomes

http${NAME}${TIME}.txt

try adding

set -xv

as the 2nd line in the shell file to see what's happening

taylor_venable 01-22-2009 06:11 AM

I wouldn't run a script I knew didn't work right as root...
at least, not without a recent backup!

renjithrajasekaran 01-24-2009 10:47 AM

Do you have privileges to write to the root folder?
Looks like that is where your application is bombing!

Linux Archive

renjithrajasekaran 01-24-2009 10:54 AM

Try writing the file to some other folder where you have write privileges. That should do the trick.
:)

Kenhelm 01-24-2009 05:28 PM

Some of the error messages indicate the script might contain carriage return characters \r (also known as ^M).
This happens if a script is edited in Windows and then run in Linux.
See this thread
http://www.linuxquestions.org/questi...ory-461400/?s=

vodka33us 01-25-2009 01:10 AM

Quote:

Originally Posted by Kenhelm (Post 3420123)
Some of the error messages indicate the script might contain carriage return characters \r (also known as ^M).
This happens if a script is edited in Windows and then run in Linux.
See this thread
http://www.linuxquestions.org/questi...ory-461400/?s=

you're right.. it works... now i want to send the file text to my windows using my windows ftp every 15 minutes. i try to make like this
Code:

HOST='192.168.0.5'
USER='vodka33us'
PASS='conan33'
ftp -i -n -u $HOST << root
user ${USER} ${PASS}

binary

put mail$NAME$TIME.txt
put http$NAME$TIME.txt
put ftp$NAME$TIME.txt
put dbase$NAME$TIME.txt
put serverinfo$NAME$TIME.txt

quit
root

rm mail$NAME$TIME.txt
rm http$NAME$TIME.txt
rm ftp$NAME$TIME.txt
rm dbase$NAME$TIME.txt
rm serverinfo$NAME$TIME.txt

SCH=$(cat /root/time_sch.txt)
if [ ! -f STOPFILE ]
then
  at -f autoscript now +$SCH minutes
fi

time_sch.txt is file that define the time. i use this because someday if i want to change the interval, i just edit the time_sch.txt

chrism01 01-25-2009 08:54 AM

Why not just use cron?


All times are GMT -5. The time now is 08:07 AM.