Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Multi File Script

Posted on 2006-12-01
1
Medium Priority
?
256 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

660 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