Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Multi File Script

Posted on 2006-12-01
1
Medium Priority
?
262 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

877 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