Solved

Multi File Script

Posted on 2006-12-01
1
223 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now