Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 367
  • Last Modified:

create script

i want to create a script that will aid in automating bash commands, such as making directories, changing permissions, moving files, etc...  

How do I do this?  I am under the impression I need to make an executable file that contains these commands, but what else needs to be done?  Is there some special syntax in the file or something else?  Any links, refrences, hints?
0
tecumsehjoe
Asked:
tecumsehjoe
2 Solutions
 
wesly_chenCommented:
Hi,

  First,
# vi auto.sh
---- auto.sh -----

#!/bin/bash

mkdir -p <directory>
chmod < permission> <directory>
mv <source path> <target path>
....
-------------------
   Second,
# chmod +x auto.sh

Then you can run that script
# ./auto.sh   <enter>

Wesly
0
 
LuxanaCommented:
HI,

to create bash script you need to :

1)
create file
touch script.sh
2)
edit file
vi script.sh
first byte of file has to contain interpreter:
#!/bin/bash
http://www.freeos.com/guides/lsst/
3)
make file executable
chmod +x script.sh
4)
run script
./script.sh
-----------------------



------------------------------
Sometimes you do not really have to use script you can use just command. For example chanage permitions for all *txt files to rwxrwxrwx in your home directory u can use command:

find /home/yourname -iname \*.txt -exec chmod 777 {} \;

0
 
owensleftfootCommented:
I would use aliases for this rather that individual scripts. Edit .bashrc in your home directory and add any aliases you like. They wont  work until you open a new shell or run source .bashrc. A couple of examples that I use -
alias xe="chmod +x"
alias log="cd /var/log"
alias mes="less /var/log/messages"
alias erc ="vi ~/.bashrc;source ~/.bashrc"
xe myfile will make myfile executable. log will change to the /var/log directory etc. You can alias several comands by putting a ; between them. I would only use scripts for more complex tasks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now