2009. 7. 27.

[Shell] FTP 자동 접근 스크립트

1
==============================================================================
#!/bin/ksh

IP=""
ID=""
PASS=""
SRC_PATH="/home/ems2/bin"

echo "----------------------------------"
echo "[$IP]와 FTP통신 하기"
echo "ID=$ID, PASSWORD=$PASS"
echo "----------------------------------"

echo "=> FTP 파일 전송(s) or 수신(r) : "\\c
read sor

LIST=""
TEMP_PATH=""
getNput=""

if [ "$sor" = "S" ] || [ "$sor" = "s" ]
then
echo "=> FTP로 전송 할 파일들 입력 : "\\c
read LIST

TEMP_PATH="./"
getNput="mput"
else
echo "=> FTP로 수신 할 파일들 입력 : "\\c
read LIST

echo "=> FTP로 수신 할 패스 입력(default : /home/ems2/bin) : "\\c
read TEMP_PATH

getNput="mget"
fi

if [ -n "$TEMP_PATH" ]
then
SRC_PATH=$TEMP_PATH
fi

ftp -n $IP << EOF
user $ID $PASS
prompt
passive
hash
bin
cd $SRC_PATH
$getNput $LIST
bye
EOF

echo "전송 완료!!"

PERM="755"

if [ "$sor" = "R" ] || [ "$sor" = "r" ]
then
echo "=> 수신한 파일들의 퍼미션 입력(default : 755) : "\\c
read TEMP_PERM

if [ -n "$TEMP_PATH" ]
then
PERM=$TEMP_PERM
fi

chmod $PERM $LIST
fi

exit 0

==============================================================================

2
==============================================================================
#!/bin/sh

IP=""
ID=""
PASS=""
SRC_PATH="/supp1/webapps/ims_domain/ims/ims_webapps/pid/server"

/home/wlogic81/nam/pid_monitor/.ws_01a_pid.sh > /home/wlogic81/nam/pid_monitor/logs/ws_01a_`date +%Y%m%d`.xml;

cp /home/wlogic81/nam/pid_monitor/logs/ws_01a_`date +%Y%m%d`.xml /home/wlogic81/nam/pid_monitor/ws_01a.xml;


ftp -n -v $IP << EOF
user $ID $PASS
prompt
passive
hash
bin
cd $SRC_PATH
mput ws_01a.xml
bye
EOF

==============================================================================

3
==============================================================================
#!/bin/sh
FILENAME=/hom
for user in $(cut -d: -f1 $FILENAME)
do
aaa=$user // 오늘날짜를 aaa라는 변수에 담아요
done
/usr/kerberos/bin/ftp -vn << END // crontab에서는 ftp라고 부르면 오류나요. 파일이 실제 존재하는 곳
open 211.xx.xx.xx
user user_id "password"

as
hash
prompt
lcd /home/uploading //업로드하려는 파일이 존재하는 폴더 (서버상에서)
put upfile_${aaa}.txt // upfile_20080721.txt 오늘날짜라면..
bye
END

==============================================================================


4 : 기타 순차 출력 방법
==============================================================================

#!/bin/sh

##cnt=1

##while [ $cnt -lt `cat list.txt | wc -l` ]
##do
#echo $cnt
## echo `cat -n list.txt | grep $cnt`
## cnt=`expr $cnt + 1`
## echo

# if [ $cnt == `cat list.txt | grep $cnt` ]
# then
# echo ""
# fi
##done


for line in `cat list.txt | tr -d '1'`;
do

echo $line

done

==============================================================================

댓글 없음: