How to create a simple copy script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to create a simple copy script?
# 15  
Old 09-29-2011
It ran without errors, but the main functionality isn't there, which is to copy from one place to another recursively:

Code:
Enterprise:~ user$ awk -F. 'NF{print "cp "$0" "$1".dat"}' infile
cp /Users/config/backup/install.deploy /Users/config/backup/install.dat
cp /Users/config2/backup/install.deploy /Users/config/backup/install.dat
cp /Users/config3/backup/install.deploy /Users/config/backup/install.dat

# 16  
Old 09-29-2011
Quote:
Originally Posted by DallasT
It ran without errors, but the main functionality isn't there, which is to copy from one place to another recursively:

Code:
Enterprise:~ user$ awk -F. 'NF{print "cp "$0" "$1".dat"}' infile
cp /Users/config/backup/install.deploy /Users/config/backup/install.dat
cp /Users/config2/backup/install.deploy /Users/config/backup/install.dat
cp /Users/config3/backup/install.deploy /Users/config/backup/install.dat

ok, what happens when you put the trailing '|sh' back in?
# 17  
Old 09-29-2011
The copy function is still not there.

Code:
Enterprise:~ user$ awk -F. 'NF{print "cp "$0" "$1".dat"}' infile | sh
Enterprise:~ user$

# 18  
Old 09-29-2011
Quote:
Originally Posted by DallasT
The copy function is still not there.

Code:
Enterprise:~ user$ awk -F. 'NF{print "cp "$0" "$1".dat"}' infile | sh
Enterprise:~ user$

what do you expect? There should be no output - the files get copied 'silently' (unless there're errors).
Do you see your new .dat files?
# 19  
Old 09-29-2011
The copy function did not happen.

The contents of install.deploy did not copy over to install.dat

The main idea is to take the contents of install.deploy and put them into install.dat, recursively for each directory listed in infile file.

This is what its doing:

its creating a brand-new install.dat inside the backup directory. which is not what i wanted.

My original request was:


Copy the contents of:

Code:
/var/router/system1/config/backup/install.put
/var/router/system2/config/backup/install.put
/var/router/system3/config/backup/install.put
/var/router/system4/config/backup/install.put

Over Write :


Code:
/var/router/system1/config/install.dat
/var/router/system2/config/install.dat
/var/router/system3/config/install.dat
/var/router/system4/config/install.dat

in this way, install.put becomes install.dat in config directory.

Last edited by DallasT; 09-29-2011 at 02:10 PM..
# 20  
Old 09-29-2011
This is a bit different from the original.
Try this:
Code:
nawk -F'[/.]' 'NF{print "cp " $0 " " $0 "/../"$(NF-1)".dat"}' myFile

Add a trailing '|sh' when satisfied with the output.

Last edited by vgersh99; 09-29-2011 at 02:26 PM.. Reason: forgot the leading NF
# 21  
Old 09-29-2011
ran, but the results are the same. The copy function did not occur.


Code:
Enterprise:~ user$ awk -F'[/.]' '{print "cp " $0 " " $0 "/../"$(NF-1)".dat"}' infile 
cp /Users/config/backup/install.deploy /Users/config/backup/install.deploy/../install.dat
cp /Users/config2/backup/install.deploy /Users/config2/backup/install.deploy/../install.dat
cp /Users/config3/backup/install.deploy /Users/config3/backup/install.deploy/../install.dat

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Create a simple bash backup script of a file

This is the problem: Write a script that will make a backup of a file giving it a ‘.bak’ extension & verify that it works. I have tried a number of different scripts that haven't worked and I haven't seen anything really concise and to the point via google. For brevity's sake this is one of the... (4 Replies)
Discussion started by: demet8
4 Replies

2. UNIX and Linux Applications

Really simple shell script to create oracle database

Hello , I am new in this forum and need your help as I am totally confused :confused: I read a lot of threads and tried to search a lot but did not get the exact answer to my question. I just want a simple (content wise may be long) shell script to create oracle database. In detail:... (5 Replies)
Discussion started by: rahoolm
5 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Create simple script

Dear all, I have a directory named A and some subdirectories named B, C, D with .xml files. I want to use the following command to strip the file. sed -re ':start s/<*>//g; /</ {N; b start}' file.xml > file.xml At the same time, I want to remove the blank lines using sed '/^$/d' How can... (6 Replies)
Discussion started by: corfuitl
6 Replies

5. Shell Programming and Scripting

Need to create a simple script using MD5, SSH...

Hi all, I am brand new to these forums and I am a brand new UNIX Administartor. Don't know any scripting yet :wall:, and would like to learn as my boss is slowly letting me understand everything about being a Sys/*Nix Admin. He created this script which I am trying to replicate because I lost it... (54 Replies)
Discussion started by: zixzix01
54 Replies

6. Shell Programming and Scripting

How to create a simple shell script to backup

Hello - I am in process of deleting many files which are older than 4 weeks. For example I am inside: /subsystem/prod/ Files are with various extentions, but anything older than 4 weeks should be deleted. What would be the most simplest script to acheive this? (4 Replies)
Discussion started by: DallasT
4 Replies

7. Solaris

How to create a simple background script on Solaris

I have a local account for a unix server. The idle timeout for the account is around 10 mins. I have to login to the server multiple times during the day. Is there a way to increase the idle timeout or may be a script that I can run on background so it is not idle. Something like echo date every 9... (3 Replies)
Discussion started by: vinaysa
3 Replies

8. Shell Programming and Scripting

Simple Script to create folders

Hi I want to write a small script that will create folders named from `AAAA' all the way to `ZZZZ'. That is: `AAAA' `AAAB' `AAAC' ... `AABA' `AABB' `AABC' ... `ABAA' `ABAB' `ABAC' ... `ABBA' ... `ZZZZ' (4 Replies)
Discussion started by: ksk
4 Replies

9. Shell Programming and Scripting

Create A Simple GUI For Shell Script

Hi all! Im wondering if its possible to create a GUI for a shell script I just got done writing as the people that will be using it dont like the command line all to well. Just something simple with radio buttons to select options, maybe a text field to enter a location to save the file generated... (1 Reply)
Discussion started by: Grizzly
1 Replies

10. Shell Programming and Scripting

Modifying simple commands to create a script

Can anyone direct me to a resource that explains scripting in simple terms? I have visited many sites and browsed this forum and have yet to find simple explanations. (8 Replies)
Discussion started by: rocinante
8 Replies
Login or Register to Ask a Question