My script runs twice
1 Attachment(s)
When I open the terminal / CLI my script runs twice in a row. The firs time it runs it gives in error message bash ip : command not found . The second time it runs it runs perfectly. Any ideas?
There is a picture attached to this message to show the actual error I am getting |
Here is the script that is running
#!/bin/sh # ********************************************************************** # # This script will greet the user then display # the hostname the IP address of this # computer and then sleep for 30 seconds # before exitting. # # ********************************************************************** # Say hello to the user echo Hello $USER # Display Machine IP hostname # Display IP address ip addr show eth0 # Pause 30 seconds sleep 30 |
Is this your script or part of your .bashrc or .profile?
First, if it's a part of your .bashrc or .profile, then remove #!/bin/sh. Second, ip command can be run by superuser only, that's why you're getting error of 'command not found' when it's run with normal user. So you have an option to use sudo before it. Code:
# Display IP address Code:
# Display IP address |
http://www.linuxquestions.org/questi...0/#post4920529 <-- did you do this as instructed?
|
Quote:
The general rule of thumb to make sure a command works is to use the full path and of course verify that that once provided the full path that the required user can execute it, if not, then the above may again be correct :) |
ok maybe I didnt understand what was being told to me earlier. So instead of having #!/bin/sh i should have ~/.bashrc or ~/.profile? Sorry guys I am trying to figure this all out. Im in the middle of reading a few things also. Thanks for the help
~/.bashrc or ~/.profile # ********************************************************************** # # This script will greet the user then display # the hostname the IP address of this # computer and then sleep for 30 seconds # before exitting. # # ********************************************************************** # Say hello to the user echo Hello $USER # Display Machine IP hostname # Display IP address ip addr show eth0 # Pause 30 seconds sleep 30 |
I don't know why you couldn't understand, but you just need to add following line at the end of your /home/cntuser/.bashrc or /home/cntuser/.profile file:
Code:
# Say hello to the user @Grail: You're right. I missed to mention that ip command can run with full path from normal user. |
All times are GMT -5. The time now is 09:02 PM. |