Bash, macchanger

Don´t be shy, Linux is fun! =)
Post Reply
User avatar
sun7
On the way to fame!
On the way to fame!
Posts: 41
Joined: 30 Jan 2010, 17:00
14
Contact:

Bash, macchanger

Post by sun7 »

Peace,

Anyone good in scripting able to help? I am new to scripting and want to start with something basic, like using macchanger to get a random mac address.

The command I run in the konsole is "macchanger -r wlan0"

I am looking to learn how to execute this by saving it into a script, so I can build on it more!!!!


Anyone out here able to help?
If this is not the right place to post please let me know!


Sincerely,
sun7

User avatar
lilrofl
Siliconoclast
Siliconoclast
Posts: 1363
Joined: 28 Jan 2009, 17:00
15
Location: California, USA
Contact:

Post by lilrofl »

save it as a .sh file and then make it executable with the chmod command.

chmod is a command that changes permissions, chmod +x filename.sh will add executable permissions.

Alternatively you can use a three digit number to designate permissions. The first digit represents owner permissions, the second represents group permissions and the third is other's permissions. The values are 4 = read 2 = write and 1 = executable. By adding together the numbers to attain the permission levels you are looking for you come up with a unique value for every permission set.

example:
read (4) write (2) and execute (1) gives you a value of 7, where as read (4) and write (2) gives a value of 6. So

777 would be read write and execute access to all users, where 766 would be read, write and execute for the owner of the file, and read write for everyone else.

Running the command becomes a matter or ./filename.sh
Here's an excerpt written by Carla Schroder

The easiest thing to do is put the script in a directory that is accessible to all your authorized users, which is not (for good reasons!) your home directory.

I would do it like this: first create the directory. Then create a new group owner just for the directory. Then set permissions so that only users in the group can access the directory. Then set permissions on the script so that only members of the group can read and execute it, but not edit it. It's basic Linux/Unix security to do it this way.

# mkdir /shared_scripts
# groupadd sharedthingies
# chown userme:sharedthingies /shared_scripts
# chmod 0750 /shared_scripts
# chown userme:sharedthingies scriptname
# chmod 0750 scriptname

In /etc/group, add your authorized users:
sharedthingies:x:1001:user1,user2,user3

Or make it read/executable by all users:
# chmod 0755 /shared_scripts
# chmod 0755 scriptname

You can even set execute permissions, without allowing read permissions:

# chmod 0711 scriptname

Though it's probably not necessary.
and a quick search for a chmod tutorial will reveal all the nuances of it and the chown command.

Good luck buddy.
knuffeltjes voor mijn knuffel
[img]http://i911.photobucket.com/albums/ac320/stuphsack/Sig.jpg[/img]

User avatar
bad_brain
Site Owner
Site Owner
Posts: 11636
Joined: 06 Apr 2005, 16:00
19
Location: In your eye floaters.
Contact:

Post by bad_brain »

just want to add that the .sh extension is voluntary, it's just the common way to be able to identify a file easily as shell script. Linux actually don't know file extensions (like Windows), you could also name the file myscript.homersimpson if you feel like, and you can still run it...of course you could also use no file extension at all.

for the start it's better to use the .sh extension, but if you have created a script that you will use regularly it's maybe a little more comfy to type just "myscript" instead of "myscript.sh" in order to run it.

if you want to use a script as a "command" like ping or netstat you can place it in a directory listed in the PATH variable:

Code: Select all

root@serv:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
if you place your script in /usr/bin for example you can run it simply by entering the script name, you don't have to use the full path to the script anymore. for my own scripts I usually use the /usr/local/bin directory.

:wink:
Image

Post Reply