Linux Red Hat 8.4 - ShellScript Output to Logfile - won't work

Hi,

I’ve created the following actionscript:

folder create "{storage folder of client}/RunMe"
delete "{storage folder of client}/RunMe/output.txt"
delete runme.sh

createfile until __END__
#!/bin/sh
echo Hello
__END__

move __createfile runme.sh
wait chmod  +x runme.sh
wait sh ./runme.sh 2>&1 > "{storage folder of client}/RunMe/output.txt"

The ActionScript will create the Folder but will not create the output.txt file
If I will run the runme.sh file that has been created with the same command that was written in the Client log file - with Terminal connected as Root - the Log will be created

On the Client log file , the wait statements are exited with error 0

What do you think?

{storage folder of client} is an object with many properties - and you just need the pathname

wait sh ./runme.sh 2>&1 > "{pathname of storage folder of client}/RunMe/output.txt"

Unfortunately, it does not work

At 09:45:03 -0500 - mailboxsite (http://BIGFIXSERVER:52311/cgi-bin/bfgather.exe/mailboxsite1080972547)
   Relevant - [TESTING] - Run Shell Script and redirect Output to Logfile (fixlet:16131)
   BackgroundAdviceEvaluation::StartFileLoop exception making problematic of Action 15881.fxf
At 09:45:04 -0500 -
   ActionLogMessage: (action:16131) Action signature verified for Execution
   ActionLogMessage: (action:16131) starting action
At 09:45:05 -0500 - actionsite (http://BIGFIXSERVER:52311/cgi-bin/bfgather.exe/actionsite)
   Command succeeded folder create "/var/opt/BESClient/RunMe" (action:16131)
   Command succeeded delete No '/var/opt/BESClient/RunMe/output.txt' exists to delete, no failure reported (action:16131)
   Command succeeded delete runme.sh (action:16131)
   Command succeeded createfile until  (action:16131)
   Command succeeded move __createfile runme.sh (action:16131)
   Command started - wait chmod  +x runme.sh (action:16131)
   Command succeeded (Exit Code=0) wait chmod  +x runme.sh (action:16131)
   Command started - wait sh ./runme.sh 2>&1 > "/var/opt/BESClient/RunMe/output.txt" (action:16131)
   Command succeeded (Exit Code=0) wait sh ./runme.sh 2>&1 > "/var/opt/BESClient/RunMe/output.txt" (action:16131)
At 09:45:05 -0500 -
   ActionLogMessage: (action:16131) ending action
At 09:45:05 -0500 - mailboxsite (http://BIGFIXSERVER:52311/cgi-bin/bfgather.exe/mailboxsite1080972547)
   Not Relevant - [TESTING] - Run Shell Script and redirect Output to Logfile (fixlet:16131)
At 09:45:10 -0500 -
   Report posted successfully

I’ve changed the script with the help of the following post - Sudo User access - and it’s working

folder create "{storage folder of client}/RunMe"
delete "{storage folder of client}/RunMe/output.txt"

delete __createfile
delete /tmp/bf_tmp_script.sh

createfile until __EOF
#!/bin/sh
echo Hello
__EOF

move __createfile /tmp/bf_tmp_script.sh

wait chmod 755 /tmp/bf_tmp_script.sh
wait sudo su - root -c "/tmp/bf_tmp_script.sh | tee {pathname of storage folder of client}/RunMe/output.txt"

delete /tmp/bf_tmp_script.sh

I’ve got another issue - If I’ll add an ifconfig command - the output.txt file will only show the echo Hello and not the output of the ifconfig command

folder create "{storage folder of client}/RunMe"
delete "{storage folder of client}/RunMe/output.txt"

delete __createfile
delete /tmp/bf_tmp_script.sh

createfile until __EOF
#!/bin/sh
echo Hello
ifconfig
__EOF

move __createfile /tmp/bf_tmp_script.sh

wait chmod 755 /tmp/bf_tmp_script.sh
wait sudo su - root -c "/tmp/bf_tmp_script.sh | tee {pathname of storage folder of client}/RunMe/output.txt"

delete /tmp/bf_tmp_script.sh

Ok… Got to the solution - This will Output everything into the LogFile

folder create "{storage folder of client}/RunMe"
delete "{storage folder of client}/RunMe/output.txt"

delete __createfile
delete /tmp/bf_tmp_script.sh

createfile until __EOF
#!/bin/sh
echo Hello
ip
__EOF

move __createfile /tmp/bf_tmp_script.sh

wait chmod 755 /tmp/bf_tmp_script.sh
wait sh -c "'/tmp/bf_tmp_script.sh' > '{pathname of storage folder of client}/RunMe/output.txt' 2>&1"

delete /tmp/bf_tmp_script.sh
1 Like

Hi Guys, Listen up the previous Script was working ok with Red Hat 7.9
If I’ll try it on Red Hat 8.4 - It will only show the Echo command and not the Output of the ip / ifconfig

Have you encountered such a case?