[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

10/22/2009 at 02:34PM PDT, ID: 24836269 | Points: 500
[x]
Attachment Details

Sending log output to an external file with BASH

Asked by xperttech in Microsoft Office Suite, Shell Scripting, Linux

Tags: linux, bash

While creating a file (see sample below), I'm sending output to a file, but the output is being sent upon creation of the file and then when executed. How can I limit the output to the execution only?
The "echo" commands outside and inside the script are ran sequentially. And I have the feeling the commands too. I'm new to bash. Can someone clarify this?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
echo "$(date "+%Y-%b-%d %H:%M:%S %Z") - Creating new /etc/rc.d/rc.local" >> /tmp/ks_install.log
cp /etc/rc.d/rc.local /etc/rc.d/rc.local.org
cat > /etc/rc.d/rc.local << RCLOCAL
#!/bin/bash
 
echo "$(date "+%Y-%b-%d %H:%M:%S %Z") - -- Trying to Execute /usr/bin/python /tmp/esx_nic_fix.py" >> /tmp/ks_install.log
count=\`last -x|grep "reboot" |wc -l\`
if [ $count -ge 2 ]; then
    echo "$(date "+%Y-%b-%d %H:%M:%S %Z") - -- -- Executing /usr/bin/python /tmp/esx_nic_fix.py" >> /tmp/ks_install.log
    /usr/bin/python /tmp/esx_nic_fix.py
    cp /etc/rc.d/rc.local.org /etc/rc.d/rc.local
	rm /etc/rc.d/rc.local.org
    chmod 644 /etc/rc.d/rc.local
	echo "$(date "+%Y-%b-%d %H:%M:%S %Z") - -- -- Rebooting (esx_nic_fix)..." >> /tmp/ks_install.log
    reboot
    exit 0
fi
RCLOCAL
echo "$(date "+%Y-%b-%d %H:%M:%S %Z") - Creating new /etc/rc.d/rc.local ...done" >> /tmp/ks_install.log
 
Keywords: Sending log output to an external file w…
 
Loading Advertisement...
 
[+][-]10/22/09 02:56 PM, ID: 25639482

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/22/09 07:47 PM, ID: 25641016

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/22/09 08:32 PM, ID: 25641186

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/23/09 06:50 AM, ID: 25644384

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625