Unix Shell - Help with some shell script and ssh command problems...

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > April 2005 > Help with some shell script and ssh command problems...





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Help with some shell script and ssh command problems...
Baz

2005-04-21, 2:54 am

Hi all,

I know this might be a little off the topic but i know this group can help
me with my questions.

I am trying to execute a ssh command from a shell script. When execute, this
script build.sh fine if i do: ./build.sh

However, if i do: ./build.sh > logfile 2>&1 ,the ssh command will hang from
time to time and i cannot figure out the reason. The same problem with using
"exec > $LOG_FILE 2>&1" within the script to capture logs.

Please help before i hurt my head scratching

I attached a couple of functions that I used SSH command within the script
and hope someone can help to identify the issue...

Thank you.

Barry

# ---------------- FUNCTIONS -----------------
#

stop_weblogic () {

echo
echo "INFO: START: stop_weblogic"
echo
echo
echo "INFO: Stopping the weblogic server in host $HOST..."
(ssh -q $HOST "cd $MODULE_BIN_DIR; ant stop_weblogic") &

echo
echo "INFO: COMPLETED: stop_weblogic"

sleep 10

}

build () {

echo
echo "INFO: START: build"

echo
echo "INFO: Creating build number."
echo
echo
(ssh -q $HOST "cd $MODULE_BIN_DIR; ant build_number")

echo
echo "INFO: DO ALL!."
echo
echo
(ssh -q $HOST "cd $MODULE_BIN_DIR; ant do_all")

echo
echo "INFO: Doing EJB."
echo
echo
(ssh -q $HOST "cd $MODULE_BIN_DIR; ant ejb_jars_uptodate")

echo
echo "INFO: COMPLETED: build"

}

# ----------------- MAIN ---------------------
#

exec > $LOG_FILE 2>&1

echo
echo "INFO: START: `date`"

notify_start;
stop_weblogic;
#get_latest;
pre_build;
#build;
post_build;
start_weblogic;
check_if_wl_server_started;
checkbuild.sh $LOG_FILE
notify_complete;

echo
echo "INFO: END: `date`"



Chris F.A. Johnson

2005-04-21, 2:54 am

On Thu, 21 Apr 2005 at 02:48 GMT, Baz wrote:
> Hi all,
>
> I know this might be a little off the topic but i know this group can help
> me with my questions.
>
> I am trying to execute a ssh command from a shell script. When execute, this
> script build.sh fine if i do: ./build.sh
>
> However, if i do: ./build.sh > logfile 2>&1 ,the ssh command will hang from
> time to time and i cannot figure out the reason. The same problem with using
> "exec > $LOG_FILE 2>&1" within the script to capture logs.
>
> Please help before i hurt my head scratching


Have you read the log file?

Have you initialized the variables, $HOST and $LOG_FILE?

Have you tried removing the -q option from the ssh commands so
that you get some messages?

Have you tried using tail -f with the log file so you can see
where it hangs?

Do the commands you are executing on the remote machine have any
interactive components?

> I attached a couple of functions that I used SSH command within the script
> and hope someone can help to identify the issue...
>
> Thank you.
>
> Barry
>
> # ---------------- FUNCTIONS -----------------
> #
>
> stop_weblogic () {
>
> echo
> echo "INFO: START: stop_weblogic"
> echo
> echo
> echo "INFO: Stopping the weblogic server in host $HOST..."
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant stop_weblogic") &


There's no need for parentheses.

> echo
> echo "INFO: COMPLETED: stop_weblogic"


How do you know it's completed if you put the command into the
background?

> sleep 10


Why don't you actually wait until the command has finished
instead of guessing how long it will take?

> }
>
> build () {
>
> echo
> echo "INFO: START: build"
>
> echo
> echo "INFO: Creating build number."
> echo
> echo
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant build_number")
>
> echo
> echo "INFO: DO ALL!."
> echo
> echo
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant do_all")
>
> echo
> echo "INFO: Doing EJB."
> echo
> echo
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant ejb_jars_uptodate")
>
> echo
> echo "INFO: COMPLETED: build"
>
> }
>
> # ----------------- MAIN ---------------------
> #
>
> exec > $LOG_FILE 2>&1
>
> echo
> echo "INFO: START: `date`"
>
> notify_start;
> stop_weblogic;
> #get_latest;
> pre_build;
> #build;
> post_build;
> start_weblogic;
> check_if_wl_server_started;
> checkbuild.sh $LOG_FILE
> notify_complete;
>
> echo
> echo "INFO: END: `date`"
>
>
>



--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Aldo

2005-04-27, 7:56 am

Hi,

On Thu, 21 Apr 2005, Chris F.A. Johnson wrote:
[vbcol=seagreen]
> On Thu, 21 Apr 2005 at 02:48 GMT, Baz wrote:

If your goal is to see what the script does, why not launching first
script <ENTER>
this will open a subshell and create typescript, in fact the log file who
registers all you are doing at that moment;
so if you run then your script without the redirs etc, maybe that will
work correctly.
doing exit stops writing from outputs to typescript.

Aldo.

Chris F.A. Johnson

2005-04-27, 5:57 pm

On Thu, 21 Apr 2005 at 02:48 GMT, Baz wrote:
> Hi all,
>
> I know this might be a little off the topic but i know this group can help
> me with my questions.
>
> I am trying to execute a ssh command from a shell script. When execute, this
> script build.sh fine if i do: ./build.sh
>
> However, if i do: ./build.sh > logfile 2>&1 ,the ssh command will hang from
> time to time and i cannot figure out the reason. The same problem with using
> "exec > $LOG_FILE 2>&1" within the script to capture logs.
>
> Please help before i hurt my head scratching


Have you read the log file?

Have you initialized the variables, $HOST and $LOG_FILE?

Have you tried removing the -q option from the ssh commands so
that you get some messages?

Have you tried using tail -f with the log file so you can see
where it hangs?

Do the commands you are executing on the remote machine have any
interactive components?

> I attached a couple of functions that I used SSH command within the script
> and hope someone can help to identify the issue...
>
> Thank you.
>
> Barry
>
> # ---------------- FUNCTIONS -----------------
> #
>
> stop_weblogic () {
>
> echo
> echo "INFO: START: stop_weblogic"
> echo
> echo
> echo "INFO: Stopping the weblogic server in host $HOST..."
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant stop_weblogic") &


There's no need for parentheses.

> echo
> echo "INFO: COMPLETED: stop_weblogic"


How do you know it's completed if you put the command into the
background?

> sleep 10


Why don't you actually wait until the command has finished
instead of guessing how long it will take?

> }
>
> build () {
>
> echo
> echo "INFO: START: build"
>
> echo
> echo "INFO: Creating build number."
> echo
> echo
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant build_number")
>
> echo
> echo "INFO: DO ALL!."
> echo
> echo
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant do_all")
>
> echo
> echo "INFO: Doing EJB."
> echo
> echo
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant ejb_jars_uptodate")
>
> echo
> echo "INFO: COMPLETED: build"
>
> }
>
> # ----------------- MAIN ---------------------
> #
>
> exec > $LOG_FILE 2>&1
>
> echo
> echo "INFO: START: `date`"
>
> notify_start;
> stop_weblogic;
> #get_latest;
> pre_build;
> #build;
> post_build;
> start_weblogic;
> check_if_wl_server_started;
> checkbuild.sh $LOG_FILE
> notify_complete;
>
> echo
> echo "INFO: END: `date`"
>
>
>



--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2005, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Daniel C. von Asmuth

2005-04-30, 6:10 pm

Baz wrote:
>
> I am trying to execute a ssh command from a shell script. When execute, this
> script build.sh fine if i do: ./build.sh
>
> However, if i do: ./build.sh > logfile 2>&1 ,the ssh command will hang from
> time to time and i cannot figure out the reason. The same problem with using
> "exec > $LOG_FILE 2>&1" within the script to capture logs.
>
>
> # ---------------- FUNCTIONS -----------------
> #
>
> stop_weblogic () {
>
> echo
> echo "INFO: START: stop_weblogic"
> echo
> echo
> echo "INFO: Stopping the weblogic server in host $HOST..."
> (ssh -q $HOST "cd $MODULE_BIN_DIR; ant stop_weblogic") &


Why are you running the above ssh command in the background?
(it may be that SSH is waiting for your input)

Kind regards,



Daniel von Asmuth

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com