1

When logging in the prompt is different than it is after executing /bin/bash

-bash-4.2$ exec bash
bash-4.2$

How do I get the - back in front of the bash. There are certain commands like tcp dump that only work in the orignal

-bash-4.2$ tcpdump -i port1 -w /home/user/$HOSTNAME-port1.pcap -c10000 -G300
tcpdump: WARNING: port1: no IPv4 address assigned
tcpdump: listening on port1, link-type EN10MB (Ethernet), capture size 65535 bytes
0 packets captured
0 packets received by filter
0 packets dropped by kernel
-bash-4.2$ exec bash
bash-4.2$ tcpdump -i port1 -w /home/user/$HOSTNAME-port1.pcap -c10000 -G300
tcpdump: port1: You don't have permission to capture on that device
(socket: Operation not permitted)

Update for @ctrl-alt-delor

-bash-4.2$ groups
nuage
-bash-4.2$ exec bash
bash-4.2$ groups
nuage

update for @Mikel

bash-4.2$ exec bash -l
bash-4.2$

Update for @Mark Plotnick

-bash-4.2$ type tcpdump
tcpdump is aliased to 'sudo /usr/sbin/tcpdump'
-bash-4.2$ exec bash
bash-4.2$ type tcpdump
tcpdump is /usr/sbin/tcpdump
[root@host nuage]# cat /etc/sudoers | grep nuage
[root@host nuage]# exit
bash-4.2$ group
bash-4.2$ groups
nuage
bash-4.2$ whoami
nuage
11
  • Can you run groups before and after. Put the result in the question. Commented Jul 11, 2018 at 16:09
  • 1
    The - just means it's a login shell. Try exec bash -l. I wonder if this is somehow related to SELinux or some other role-based access control system. But why are you doing exec bash in the first place?
    – Mikel
    Commented Jul 11, 2018 at 16:10
  • @Mikel Updated in original, this was the simplest form of the problem, the reason I need to find out how to run things as the original shell is because I must run a script and #!/bin/bash has different permissions than what was used to create the definition for the script.
    – Xander May
    Commented Jul 11, 2018 at 17:21
  • Can you show us the output of type tcpdump before and after? Commented Jul 11, 2018 at 17:37
  • 1
    Try exec -a -bash bash ; I think that ought to set things up so that your shell init files are read in by the new bash and thus you'll see all your aliases. Commented Jul 11, 2018 at 17:56

1 Answer 1

1

Problem : After executing exec bash the aliases present in the default login prompt are lost causing some commands to not work as expected, such as tcpdump in the following example

-bash-4.2$ tcpdump -i port1 -w /home/user/$HOSTNAME-port1.pcap -c10000 -G300
tcpdump: WARNING: port1: no IPv4 address assigned
tcpdump: listening on port1, link-type EN10MB (Ethernet), capture size 65535 bytes
0 packets captured
0 packets received by filter
0 packets dropped by kernel
-bash-4.2$ exec bash
bash-4.2$ tcpdump -i port1 -w /home/user/$HOSTNAME-port1.pcap -c10000 -G300
tcpdump: port1: You don't have permission to capture on that device
(socket: Operation not permitted)

The Fix : You can do what I did and figure out how the aliases change between the different prompts

-bash-4.2$ type tcpdump
tcpdump is aliased to 'sudo /usr/sbin/tcpdump'
-bash-4.2$ exec bash
bash-4.2$ type tcpdump
tcpdump is /usr/sbin/tcpdump

and then change the script to use those sudo tcpdump instead of plain tcpdump.

Or alternatively you can restore all the aliases present in the original prompt by running exec -a -bash bash (which is apaprently not recommended, see @ctrl-alt-delor's comment)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .