LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 01-21-2009, 04:23 AM   #1
vodka33us
LQ Newbie
 
Registered: Jun 2008
Posts: 10

Rep: Reputation: 0
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

Last edited by vodka33us; 01-22-2009 at 04:27 AM.
 
Old 01-21-2009, 04:28 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
??? of course we can't... how can we know what the issue is if we can't see the script??
 
Old 01-22-2009, 01:20 AM   #3
vodka33us
LQ Newbie
 
Registered: Jun 2008
Posts: 10

Original Poster
Rep: Reputation: 0
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
 
Old 01-22-2009, 01:39 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
gah, don't edit the original thread... how confusing is that?
 
Old 01-22-2009, 05:02 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
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
 
Old 01-22-2009, 05:11 AM   #6
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 40
I wouldn't run a script I knew didn't work right as root...
at least, not without a recent backup!
 
Old 01-24-2009, 09:47 AM   #7
renjithrajasekaran
Member
 
Registered: Jan 2009
Posts: 29

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

Linux Archive

Last edited by renjithrajasekaran; 01-25-2009 at 03:09 AM.
 
Old 01-24-2009, 09:54 AM   #8
renjithrajasekaran
Member
 
Registered: Jan 2009
Posts: 29

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

Last edited by renjithrajasekaran; 01-24-2009 at 09:55 AM.
 
Old 01-24-2009, 04:28 PM   #9
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 329

Rep: Reputation: 140Reputation: 140
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=
 
Old 01-25-2009, 12:10 AM   #10
vodka33us
LQ Newbie
 
Registered: Jun 2008
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Kenhelm View Post
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
 
Old 01-25-2009, 07:54 AM   #11
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Why not just use cron?
 
  


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
htaccess + invalid command dianarani Linux - Server 1 09-19-2008 09:02 PM
mod_perl error Invalid command 'PerlOptions' agentc0re Slackware 6 05-24-2007 01:22 PM
Apache error - Invalid Command 'AddType'... humbletech99 Linux - Networking 0 11-28-2005 08:22 AM
Invalid command : monitor tekn0phile Linux - Hardware 0 10-18-2003 07:04 AM
invalid dial command haknot Linux - General 0 03-01-2001 07:20 AM


All times are GMT -5. The time now is 03:55 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration