Solved

Multi File Script

Posted on 2006-12-01
1
239 Views
Last Modified: 2013-12-16
Ok, so I have a samba server and want to create a logon batch script for each user using a template called template.bat. I need a quick way of copying template.bat to other file names for example:

rather than running the command "cp templates.bat agent5000.bat" and then the same again for agent5001/5002/5003 I want a script that will copy template.bat to 100 files from agent5000.bat to agent6000.bat. Any ideas?

0
Comment
Question by:blaadom
1 Comment
 
LVL 3

Accepted Solution

by:
jhartzen earned 500 total points
ID: 18053331
Hi there blaadom.  A small script will do the trick for you.

Put the text (lines) into a file, for example ~/manycopies
-----cut here-----
#!/bin/bash

X=5000   ; # Set starting value, using the variable X as a counter ...

# Repeat these statents in a loop until we reach the value "6000".
while [ $X -le 6000 ]
do
   cp templates.bat agent${X}.bat ;    # Create a copy
   let X+=1 ;    # Increment the counter
done
-----cut here-----

Obviously you must exclude the "cut here" lines .... note that the #!/bin/bash line must be the first line.  In all other cases you can use free indentation, leave open lines in between, etc.

Once you have saved the text file, make it executable using the following command:
chmod +rx ~/manycopies

(I am asuming you saved it as "~/manycopies - note that ~/.... means "in my home directory".)

Now execute the program ...
~/manycopies

Note also that the script will operate in the current working directory, not neccesarily your home directory.
Cheers,
  _Johan
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question