LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Remote execution of command to find available space logging in ftp mode. (https://www.linuxquestions.org/questions/linux-newbie-8/remote-execution-of-command-to-find-available-space-logging-in-ftp-mode-617732/)

unixuser 01-31-2008 01:33 PM

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

0.o 02-01-2008 11:20 AM

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?

unixuser 02-03-2008 03:56 PM

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

unixuser 10-09-2008 08:51 AM

Quote:

Originally Posted by unixuser (Post 3044898)
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.


All times are GMT -5. The time now is 02:17 AM.