Tag Archives: CMD

Sftp files between servers

By nmm_dba

I am writing a shell script to copy sybase related .dump files from one to another aix server and visa versa.

Please help me do the following

The script does the following:
– check directory exists
– copy dump files
– copy is done for multiple database
– checks databases, if one database does not exist, the script should skip that database and move to the next database.

Started the script:
==============

Code:

#!/usr/bin/ksh
# *****************************************************************************
# Script Name: sftp_dump_files.ksh
# Description: Performs sFTP put of exported dump files
#
# Syntax:
# sftp_dump_files.ksh -d -r
#
# Required parameters:
# lv_dbname - name of schema dump to sFTP
# lv_rfc - change number [ format CHGXXXX ]
# *****************************************************************************
#
# Execute to setup global variables
. ${APPS}/db_batch/common/.batchenv
# *****************************************************************************
# Function - Display parameter usage and terminate the job
# *****************************************************************************
CMD=`basename $0`
display_usage()
{
echo "==============================================================================="
echo "Script Name: ${CMD}"
echo "Description: Performs sFTP put of exported dump files"
echo ""
echo "Usage:"
echo " ${CMD} -r "
echo ""
echo "Required parameters:"
echo " lv_dbname - name of database dump to sFTP"
echo " lv_rfc - change number [ format CHGXXXX ]"
echo "==============================================================================="
exit 1
}
# *****************************************************************************
# Parse input parameter
# *****************************************************************************
set -- $(getopt u:r: $*)
if [ $? -ne 0 ]
then
echo "ERROR: Insufficient arguments."
display_usage
fi
count_r=0
for o in $(getopt u:r: $*)
do
case $o in
-u) lv_dbname="$2"; count_u=$(expr $count_u + 1); shift 2;;
-r) lv_rfc="$2"; count_r=$(expr $count_r + 1); shift 2;;
--) shift; break;;
esac
done
# Abort if there are insufficient arguments
if [ $count_u -ne 1 ] || [ $count_r -ne 1 ]
then
echo "ERROR: Insufficient arguments."
display_usage
fi
# Export local variables and force uppercase
export lv_dbname="`echo ${lv_dbname} | tr '[:lower:]' '[:upper:]'`"
export lv_rfc="`echo ${lv_rfc} | tr '[:lower:]' '[:upper:]'`"
# *****************************************************************************
# Setup local step variables
# *****************************************************************************
# Local job variables
export lv_job_path="${DBBATCH}/CR/${lv_rfc}"
export lv_common_path="${lv_job_path}/common"
export lv_shell_path="${lv_job_path}/shell"
export lv_sql_path="${lv_job_path}/sql"
export lv_log_path="${lv_job_path}/log"
mkdir -p ${lv_common_path} ${lv_shell_path} ${lv_sql_path} ${lv_log_path}
# Setup local step variables
lv_step_name=sftp_dump_files
lv_step_log_file=${lv_log_path}/${lv_step_name}.log
# Additional local variables
lv_retcode=0
lv_exitcode=0
# *****************************************************************************
# Main

From: http://www.unix.com/shell-programming-scripting/221615-sftp-files-between-servers.html

How do i deal with values on multiple lines?

By chandika_diran

Hi,

I have a file which has the contents:
sh-4.2# pwd
/tmp
sh-4.2# cat servernfiles
server1 /var/tmp/file
server2 /var/tmp/file1

I want to manage each line one after the other. I have this basic script :

#!/bin/sh

HOST=`cat /tmp/servernfiles | awk ‘{print $1}’`
CMD=`cat /tmp/servernfiles | awk ‘{print $2}’`

for i in `cat /tmp/servernfiles`
do
echo $HOST,$CMD
done

When i run the script, i was expecting to get the output of each line (i.e “server1 /var/tmp/file” followed by the other line “server2 /var/tmp/file1” ) but get this:

sh-4.2# ./servern
server1 server2,/var/tmp/file /var/tmp/file1
server1 server2,/var/tmp/file /var/tmp/file1
server1 server2,/var/tmp/file /var/tmp/file1
server1 server2,/var/tmp/file /var/tmp/file1

Can anyone please explain why this is or how i can output of each line individually?

To put this into context, im going to develop my script so it can recursively log onto each host and output the /var/tmp/file – but this bit i can do once i can figure out why im getting this first problem

Thanks!

From: http://www.unix.com/shell-programming-scripting/220915-how-do-i-deal-values-multiple-lines.html

Script returningng 0

By donatas1234

hello i write a script which calculate free space but he always is 0 thats wrong with my script?


getFileSystemPerformanceData()
{

if [ -r /etc/issue ] ; then
if grep -q "Ubuntu" /etc/issue ; then
CMD="df -lP | grep -v "/home" | grep -v "/dev/mapper/VolGroup-lv_root""
elif grep -q "Mageia" /etc/issue; then
CMD="df -lP | sed -e '2d'"
elif grep -q "Fedora" /etc/issue; then
CMD="df -lP | grep -v "/home" | grep -v "/dev/mapper/VolGroup-lv_root""
else
CMD="df -lP"
fi
else
CMD="df -lP"
fi
OUTPUT=`$CMD`
echo "$OUTPUT" |
( # Skip the header-line
read IGNORED
SUM=0
SIZE=0
while read FS SIZE USED AVAIL PCT MOUNTED ; do
SIZE=`echo "$AVAIL 1024" | awk '{print $1/$2}'`
SUM=`echo "$SUM $SIZE" | awk '{print $1 + $2}'`
done
PERFCLASS=LogicalDisk;PERFINSTANCE=$FS;PERFMETRIC='Avail Megabytes';PERFINT=0;PERFSAMP=1;PERFAVG=$SUM;PERFMIN=$PERFAVG;PERFMAX=$PERFAVG;writePerformanceDataXml
)


}

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Ssh = ssh expect and keep everything not change inculde parameter postion

By yanglei_fageI have write a script which contains

Code:
ssh -p 12345 dcplatform@10.125.42.50
ssh 127.0.0.1 -p 5555 “$CMD
ssh root@$GUEST_IP “$CMD
before I use public key, it works well, now I want to change to “expect”, BUT I don’t want to change above code and “parameter position”

I can post a expect template can some one help me to modify it

Code:
#cat sshx
#!/usr/bin/expect

set timeout 60
set host [lindex $argv 0]
set name root
set password root

spawn ssh $host -l $name
expect {
“(yes/no)?” {
send “yesn”
expect “assword:”
send “$passwordn”
}
“assword:” {
send “$passwordn”
}
}
send “uname -an”
#send “exitr”
expect eof
exit

Code:
sshx -p 12345 dcplatform@10.125.42.50
sshx 127.0.0.1 -p 5555 “$CMD
sshx root@$GUEST_IP “$CMD
To goal is
Above cmd will not need to input password, I can’t use public keys now, becasue I remote filesystem is readonly

Lei
Source: The UNIX and Linux Forums

Where is wrong with my default value?

By yanglei_fage
Code:
lyang0@lyang0-OptiPlex-755:/tmp$ ./fg.sh
………………………….
ssh to the guest …..
………………………….
./fg.sh: 18: :ls: not found

Code:
lyang0@lyang0-OptiPlex-755:/tmp$ cat fg.sh
#!/bin/sh
DEFAULT_CMD=”ls /boot/”
ssh_to_guest()
{
echo “………………………….”
echo “ssh to the guest …..”
echo “………………………….”
CMD=”$1″
:${CMD:=$DEFAULT_CMD}
if ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@128.224.165.205 “${CMD}”;then
echo “pass”
else
echo “fail”
fi

}
ssh_to_guest

Source: The UNIX and Linux Forums

Where is wrong with my defualt value?

By yanglei_fage
Code:
lyang0@lyang0-OptiPlex-755:/tmp$ ./fg.sh
………………………….
ssh to the guest …..
………………………….
./fg.sh: 18: :ls: not found

Code:
lyang0@lyang0-OptiPlex-755:/tmp$ cat fg.sh
#!/bin/sh
DEFAULT_CMD=”ls /boot/”
ssh_to_guest()
{
echo “………………………….”
echo “ssh to the guest …..”
echo “………………………….”
CMD=”$1″
:${CMD:=$DEFAULT_CMD}
if ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@128.224.165.205 “${CMD}”;then
echo “pass”
else
echo “fail”
fi

}
ssh_to_guest

Source: The UNIX and Linux Forums