LinuxQuestions.org
Register a domain and help support LQ
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 01-31-2008, 02:33 PM   #1
unixuser
LQ Newbie
 
Registered: Jan 2008
Posts: 3
Blog Entries: 1

Rep: Reputation: 0
Remote execution of command to find available space logging in ftp mode.


i have the below program to connect to remote unix box and to find the space on the other machine being at the ftp prompt.

i dont want to use ssh, etc apart from this approach. can any1 help me out in this regard?
`ls -ld /app | awk '{ print $5; }' > percent.txt`
the above command is working fine but how to find the exact space utilized in that particular directory? Coz i cannot use df -k command at ftp prompt. if i use ! mark !df -k it gives the current box space and not the space of the box where i am connected to with ftp

#!/bin/sh

filesystems="/app"

export INDIR=/app/
FTP_HOST1=ABCDEF1
FTP_HOST2=ABCDEF2
FTP_HOST3=ABCDEF3
FTP_HOST4=ABCDEF4
FTP_HOST5=ABCDEF11
FTP_HOST6=ABCDEF7701
FTP_HOST7=ABCDEF7702
FTP_HOST8=ABCDEF7709
FTP_HOST9=ABCDEF7710
FTP_HOST10=ABCDEF7713
FTP_HOST11=ABCDEF7714
FTP_HOST12=ABCDEF7716
FTP_HOST13=ABCDEF7718

FTP_USER_NAME=ftp
FTP_PASSWD=xfffffx

echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF1
open $FTP_HOST1
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF1
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low for $FTP_HOST1" > dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF2
open $FTP_HOST2
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF2
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST2" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF3
open $FTP_HOST3
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF3
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST3" >> dsreport.txt

fi
done < percent.txt



echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF4
open $FTP_HOST4
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF4
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST4" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF5
open $FTP_HOST5
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF5
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST5" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF6
open $FTP_HOST6
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF6
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST6" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF7
open $FTP_HOST7
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF7
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST7" >> dsreport.txt

fi
done < percent.txt



echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF8
open $FTP_HOST8
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF8
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST8" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF9
open $FTP_HOST9
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF9
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST9" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF10
open $FTP_HOST10
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF10
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST10" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF11
open $FTP_HOST11
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF11
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST11" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF12
open $FTP_HOST12
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF12
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST12" >> dsreport.txt

fi
done < percent.txt


echo -e "\n=>\n=><$i>Checking for production box Disk Space\n=>"
ftp -vin <<EOF13
open $FTP_HOST13
user $FTP_USER_NAME $FTP_PASSWD
lcd /app
`ls -ld /app | awk '{ print $5; }' > percent.txt`
bye
EOF13
while read line
do

if [ $line -ge 12288 ]
then
echo "Disk space very low $FTP_HOST13" >> dsreport.tx

fi
done < percent.txt

Last edited by unixuser; 01-31-2008 at 02:36 PM.
 
Old 02-01-2008, 12:20 PM   #2
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
If you use the utility 'expect', it will make your life WAY easier. That utility should come with a script called autoexpect. Once you have it, just run the 'autoexpect' command and issue the commands that you wish to use. Once that is done, type 'exit'. That will drop you out of the script creation and write the file... it defaults to script.exp. Once that is done, edit the file to accept positional variables.

Here's an example:
Code:
set force_conservative 0  ;# set to 1 to force conservative mode even if
                          ;# script wasn't run conservatively originally
if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} {
                sleep .1
                exp_send -s -- $arg
        }
}


set timeout -1
set host [lindex $argv 0]
set ip [lindex $argv 1]
spawn telnet $host
match_max 100000
expect -exact "Username: "
send -- "user\r"
expect -exact "Password: "
send -- "pass\r"
expect -exact "HR>"
send -- "en\r"
expect -exact "Password: "
send -- "pass\r"
expect -exact "HR#"
send -- "ping\r"
expect -exact "Protocol \[ip\]: "
send -- "\r"
expect -exact "Target IP address: "
send -- "$ip\r"
expect -exact "Repeat count \[5\]: "
send -- "10\r"
expect -exact "Datagram size \[100\]: "
send -- "36\r"
expect -exact "Timeout in seconds \[2\]: "
send -- "1\r"
expect -exact "Extended commands \[n\]: "
send -- "\r"
expect -exact "Sweep range of sizes \[n\]: "
send -- "\r"
expect -exact "HR#"
send -- "q\r"
expect eof
In this example we have created a script to login to a cisco router and ping hosts. If you create a file with a list of ip addresses, each on their seperate lines, then use something like this:

Code:
for ip in `cat file`
    do
          /path/to/script.exp $1
          more code...
    done
Although now that i read your post completely, it seems as though that what i have suggested wont work. Why do you want to use FTP to get the size of the directory?

Last edited by 0.o; 02-01-2008 at 12:23 PM.
 
Old 02-03-2008, 04:56 PM   #3
unixuser
LQ Newbie
 
Registered: Jan 2008
Posts: 3
Blog Entries: 1

Original Poster
Rep: Reputation: 0
y we want to log in FTP mode is that. this script runs on production unix boxes. and we dont have permissions to login as anonymous user etc.... so found this approach to find the disk space (dont know this works r not). all the unix boxes are having weblogic instanes running. as the weblogic logs pile up, the disk space minimizes to ZERO, which results in PROD weblogic instance to go down. to avoid that we want to define a crontab job which runs every one hr on the prod boxes to check the disk space. and that too the script should run only from one of the PROD box and log into other PROD boxes and if the disk space is more than 90% should send an email to the concerned people

Last edited by unixuser; 10-09-2008 at 09:46 AM.
 
Old 10-09-2008, 09:51 AM   #4
unixuser
LQ Newbie
 
Registered: Jan 2008
Posts: 3
Blog Entries: 1

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unixuser View Post
y we want to log in FTP mode is that. this script runs on production unix boxes. and we dont have permissions to login as anonymous user etc.... so found this approach to find the disk space (dont know this works r not). all the unix boxes are having weblogic instanes running. as the weblogic logs pile up, the disk space minimizes to ZERO, which results in PROD weblogic instance to go down. to avoid that we want to define a crontab job which runs every one hr on the prod boxes to check the disk space. and that too the script should run only from one of the PROD box and log into other PROD boxes and if the disk space is more than 90% should send an email to the concerned people
Any update on my problem please do reply to this thread.
 
  


Reply

Tags
available, command, execution, find, ftp, logging, mode, remote, space


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
automated remote command execution using telnet sharad Linux - General 1 01-17-2007 01:59 AM
Automated execution of a command on a remote system via SSH GUIPenguin Linux - General 1 03-01-2006 12:23 AM
ssh : remote command execution doesn't work for modifying env variables pypieuvre Programming 10 02-24-2006 10:50 AM
LXer: Adodb Multiple Test Scripts Remote Command Execution ... LXer Syndicated Linux News 0 01-09-2006 07:01 PM
Remote Command Execution via mobile phone Sammy2ooo Linux - Software 6 06-27-2003 04:42 AM


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