-3

I have a simple script that terminates some processes and closes ports as below. I am running metasploitable.

fuser script

However, whenever I run this, it gives the below error. (note that on this file everyone has permissions)

error

tony9099
  • 137

2 Answers2

1

to run a script it must be executable chmod +x portblock.sh then to run it you must add ./ in the beginning

./portblock.sh
Dababi
  • 3,355
  • 24
  • 23
  • I am not getting the error : -bash: ./portblock.sh /bin/bash^M: bad interpreter: No such file or directory – tony9099 Dec 02 '16 at 14:45
  • 1
    Looks like you have a dos line ending file. The clue is the ^M. You need to re-save the file using Unix line endings. – Dababi Dec 02 '16 at 14:48
0

First of all make sure you have executable permission for your script.

And then,

Run your script using ./portblock.sh or using sh portblock.sh.

If you don't like to run the script with above mentioned way then update your PATH variable to the script directory.

Thushi
  • 9,498
  • I have 777 permissions on it...I am not getting the error : -bash: ./portblock.sh /bin/bash^M: bad interpreter: No such file or directory – tony9099 Dec 02 '16 at 14:45
  • file was edited by windows, you must run dos2unix portblock.sh – Archemar Dec 02 '16 at 14:47
  • @Archemar thanks. But I need to install the program which seems not to be working in Exploitable – tony9099 Dec 02 '16 at 14:49
  • see http://stackoverflow.com/questions/14372645/convert-dos2unix-line-endings-for-all-files-in-a-directory (hint: sed -i s/\r// ) – Archemar Dec 02 '16 at 14:53
  • 1
    Yes, as @Archemar said, You should run dos2unix. Line endings should use LF not CRLF. – Thushi Dec 02 '16 at 15:05
  • its fine guys, the commands were very few so i created a new file using cat and it works fine thanks. – tony9099 Dec 02 '16 at 15:27