LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-07-2018, 06:59 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Understanding of set -x output when ran against Bash script


I'm debugging a Bash script and using set -x to test.

Code:
set -x frags.sh

The code seems to work ok, and the final line shows the following:

Code:
++ printf '\033]0;%s@%s:%s\007' root localhost '!~/scripts'
I'm having trouble figuring out part of the output. I understand the user is Root, the hostname of the VM that I ran the script on is localhost and the directory of where I ran the script.

I don't understand the first part of the output. Can someone shed a little more light on this?

thanks
 
Old 03-07-2018, 08:15 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,784

Rep: Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937Reputation: 5937
That first part looks like an xterm control sequence which changes the title bar of window. It should display
root@localhost:~/scripts

http://invisible-island.net/xterm/ct...ystem-Commands
 
Old 03-08-2018, 02:08 AM   #3
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Rep: Reputation: 15
what's your code line.. show it and the debug o/p to all us side by side here and now, so we can discuss together

Last edited by BudiKusasi; 03-08-2018 at 02:10 AM.
 
Old 03-08-2018, 02:42 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
yes, please show the original (line) command and probably a few lines of trace before/after....
 
Old 03-15-2018, 07:27 PM   #5
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Ok...I posted the wrong name of the script. It should be rhel6_stig_fix.sh, not frag.sh.

I think my script damaged the guest VM too, as I can't run certain commands anymore...and had to mount a usb drive to pull off this code in order share it as I don't have Guest Additions installed, and samba wasn't working either to share with Win 7 desktop.

Here is the output when running set -x against the script file:

Code:
set -x rhel6_stig_fix.sh
++printf '\033]0;%s@%s:%s\007' root localhost '~/scripts'

Here is the script in its entirety

Code:
#!/bin/bash 

touch /var/tmp/stig_output.txt
echo
echo `date` >> /var/tmp/stig_output.txt 

echo 
echo "Applying RHEL6 STIGs"
echo "Backing up important files to /root/bkup before applying STIGs"
sleep 30
mkdir -p /root/bkup
cp /etc/pam.d/system-auth /root/bkup
cp /etc/pam.d/system-auth-ac /root/bkup
cp /etc/ssh/sshd_config /root/bkup

echo 
echo "############################################"
echo "creating RHEL6 stig log file under /var/tmp "
echo "############################################"
echo

# CAT 1
echo
echo "rhel-06-0000008  rule id  sv-50276r3  vuln id v-38476" >> /var/tmp/stig_output.txt
rpm -q gpg-pubkey >> /var/tmp/stig_output.txt

# CAT 1
echo
echo "rhel-06-000019  rule id  sv-50292r1_rule  vule id v-38491" >> /var/tmp/stig_output.txt 
if [ -f /etc/hosts.equiv ];
then 
     echo "File hosts.equiv exist in /etc." >> /var/tmp/stig_output.txt 
else 
     echo "File hosts.equiv does not exist in /etc." >> /var/tmp/stig_output.txt 
fi  

# CAT 1
# still working on this stig
echo 

nullok_var = nullok 

echo "rhel-06-000030  rule id  sv-50298r2_rule  vuln id v-38497" >> /var/tmp/stig_output.txt
grep "nullok" /etc/pam.d/system-auth >> /var/tmp/stig_output.txt 
sed -i '/nullok/d' /etc/pam.d/system-auth 
if [ grep -q $nullok /etc/pam.d/system-auth ] ; 
then 
 echo "nullok has been removed from /etc/pam.d/system-auth" >> /var/tmp/stig_output.txt 
else 
 echo "nullok still in /etc/pam.d/system-auth...please fix" >> /var/tmp/stig_output.txt  

# CAT 1 
echo 
echo "rhel-06-000206  rule id  sv-50388r1_rule  vuln id v-38587" >> /var/tmp/stig_output.txt

telnet_package=telnet-server

if rpm -qa | grep -q $telnet_package; 
then 
     echo "$telnet_package is installed"
else
     echo "$telnet_package is NOT installed"
fi

# CAT 1
echo 
echo "rhel-06-000211  rule id  sv-50390r2_rule  vuln id v-38589" >> /var/tmp/stig_output.txt 

if pgrep telnet > /dev/null 2>&1
then 
     echo "Telnet is running, turn it off" >> /var/tmp/stig_output.txt && chkconfig --level 2345 off telnet
else  
     echo "Telnet is NOT running" >> /var/tmp/stig_output.txt
fi 


# CAT 1
echo 
echo "rhel-06-000213  rule id  sv-50392r1_rule  vuln id v-38591" >> /var/tmp/stig_output.txt 

rsh_server_package=rsh-server

if rpm -qa | grep -q $rsh_server_package; 
then 
     echo "$rsh_server_package is installed...removing" && rpm -e $rsh_server_package >> /var/tmp/stig_output.txt
else 
     echo "$rsh_server_package is NOT installed" >> /var/tmp/stig_output.txt
fi


# CAT 1 
echo 
echo "rhel-06-000241  rule id  sv-50395r2_rule  vuln id v-38594" >> /var/tmp/stig_output.txt 

if pgrep rsh > /dev/null 2>&1
then 
    echo "rsh is running, turn it off" >> /var/tmp/stig_output.txt && chkconfig --level 2345 off rsh
else 
    echo "rsh is NOT running" >> /var/tmp/stig_output.txt
fi


# CAT 1 
echo 
echo "rhel-06-000216  rule id  sv-50399r2_rule  vuln id v-38598" >> /var/tmp/stig_output.txt

if pgrep rexec > /dev/null 2>&1 
then 
     echo "rexec is running, turn it off" >> /var/tmp/stig_output.txt && chkconfig --level 2345 off rexec
else 
     echo "rexec is NOT running" >> /var/tmp/stig_output.txt 
fi 


# CAT 1
echo 
echo "rhel-06-000218  rule id  sv-50403r2_rule  vuln id v-38602" >> /var/tmp/stig_output.txt


# CAT 1 
echo 
echo "rhel-06-000227  rule id  sv-50408r1_rule  vuln id v-38607" >> /var/tmp/stig_output.txt

if grep -i 'Protocol 2' /etc/ssh/sshd_configi >> /var/tmp/stig_output.txt
then 
    echo "Protocol 2 exist in /etc/ssh/sshd_config" >> /var/tmp/stig_output.txt
else 
    echo "Protocol 2 DOES NOT exist in /etc/ssh/sshd_config, please add" >> /var/tmp/stig_output.txt
fi


# CAT 1 
echo 
echo "rhel-06-000239  rule id  sv-50415r1_rule  vuln id v-38614" >> /var/tmp/stig_output.txt

grep -i 'PermitEmptyPasswords' | tr -d '#' | service sshd restart && echo 'Remove # from PermitEmpytPasswords' >> /var/tmp/stig_output.txt 

# if grep -i 'PermitEmptyPasswords' /etc/ssh/sshd_config >> /var/tmp/stig_output.txt 
# then 
#     echo  && service restart sshd 


# CAT 1
echo 
echo 'rhel-06-000286  rule id  sv-50469r3_rule  vuln id v-38668' >> /var/tmp/stig_output.txt

touch /etc/init/control-alt-delete.override 
echo "exec /usr/bin/logger -p security.info \"Ctrl-Alt-Delete pressed\"" > /etc/init/control-alt-delete.override 


# CAT 1
echo 
echo "rhel-06-000309'  rule id  sv-50478r1_rule  vuln id v-38677" >> /var/tmp/stig_output.txt

if grep -i 'insecure_locks' /etc/exports ; then 
     echo "Remove all instancs of insecure locks from /etc/exports" >> /var/tmp/stig_output.txt
else 
     echo "No insecure_locks exist in /etc/exports...ok" >> /var/tmp/stig_output.txt


# CAT 1 
echo 
echo "rhel-06-000338  rule id  sv-50502r1_rule  vuln id v-38701" >> /var/tmp/stig_output.txt

touch /etc/xinetd.d/tftp 
echo "server_args = -s /var/lib/tftpboot" > /etc/xinetd.d/tftp
echo "tftp file created under /etc/xinetd.d and populated with the correct info...ok" >> /var/tmp/stig_output.txt


# CAT 1 
echo 
echo "rhel-06-000341  rule id  sv-50454r1_rule  vuln id v-38653" >> /var/tmp/stig_output.txt

mkdir -p /etc/snmp && touch /etc/snmp/snmpd.conf

service snmpd restart 

 
echo
echo "######################################"
echo "Finished Applying RHEL6 STIGS, see log for more information"
echo "######################################"
echo
 
Old 03-16-2018, 03:52 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
I missed it in post #1, but set -x <script> is definitely wrong.
You need to put set -xv in the script itself, at the beginning, just after the shebang (#!/bin/bash).
Or you need to invoke your script as: bash -xv <script>.
The printf you asked about is coming from your current shell (because set -x was invoked in your actual shell), it is not related to the script you wanted to execute at all. Most probably it is related to the prompt configuration (see the variable PS1).
 
  


Reply

Tags
bash, set



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pipe output of local script, ran on remote machine, to local python script trendal Programming 17 07-04-2016 01:56 AM
Apache ran shell script / no output tnrooster Linux - Software 2 02-03-2011 11:32 AM
Help understanding a bash script cylon Linux - Newbie 4 09-16-2009 10:04 AM
Running a command as another user in a bash script ran as root? camphor Programming 2 03-29-2009 03:11 PM
bash script, understanding variables antis Programming 5 11-15-2007 04:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration