Solved

Multi File Script

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
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.:
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…

713 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