ksh shell scripting to copy a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh shell scripting to copy a file
# 1  
Old 04-26-2013
ksh shell scripting to copy a file

Hi. I am a new Unix admin and I've been tasked to write a ksh script that copies my .profile into my /home directory on all servers. I'm new to this and having a difficult time scripting it. Any ideas?

Last edited by joeyg; 04-26-2013 at 12:54 PM..
# 2  
Old 04-26-2013
What have you tried?
# 3  
Old 04-26-2013
I've copied all of the host names into hosts.txt. I need the script to call out to hosts.txt and copy my profile into the home directory of all servers in hosts.txt

Code:
if ['echo $host' = "hosts.txt"]
then
sftp .profile /home/directory
while read "hosts.txt
sftp .profile /home/directory
fi

# 4  
Old 04-26-2013
what is this 'echo $host' supposed to do?

For copying single files like this, scp looks more appropriate than sftp. Use it like [icode]sftp /path/to/localfile username@host:/path/to/remotefile[icode]

Code:
while read HOSTNAME
do
        scp .profile $HOSTNAME:
done < hosts.txt

# 5  
Old 04-26-2013
echo the hostname and match it to hosts.txt
# 6  
Old 04-26-2013
Oh, so you want to avoid the host copying to itself...

Code:
while read HOST
do
        [ "$HOSTNAME" = "$HOST" ] && continue
        scp .profile $HOST:
done < hosts.txt

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 04-26-2013
Yes. I want to avoid the host copying to itself. I do need the .profile in my /home/directory.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem scripting a copy and renaming shell executable

I also posted this on macrumors forum, then i realized that this is a more suitable forum for matters like this. I apologize for the username, I was looking at a bag of doritos when it asked me for a username. lol I need a program (see below for what I've tried) and I think a shell program will... (23 Replies)
Discussion started by: ilovedoritos
23 Replies

2. Shell Programming and Scripting

How to get the consecutive last 10 week day date using UNIX ksh shell scripting?

Hi, i am writing a ksh shell script to check the last month end date whether it is falling in last 10 week day date, I am not sure How to use "Mr. Perderabo's date calculator", Could you Please let me know how to use to get my requirement, I tried my own script but duplicate week day and... (5 Replies)
Discussion started by: karthikram
5 Replies

3. Shell Programming and Scripting

Shell Scripting: Copy Files with Today's date

I was wondering the best way about finding files that were created today and copy them to a directory (grep ?). There can be multiple files for todays date or none. I am looking to copy all of the .lis files for todays date. I may need to modify the filename to include todays date but for the... (4 Replies)
Discussion started by: smkremer
4 Replies

4. Shell Programming and Scripting

Use case insensitive variable in ksh shell scripting using sed or awk

I am using a variable called $variable in a pattern search to print from a starting variable to a constant value. the variable search should be case in sensitive. i tired using Ip at the end in the below command. but in ksh it is not working. sed -n "/$variable/,/constant/p" file i also... (11 Replies)
Discussion started by: johnjs
11 Replies

5. Shell Programming and Scripting

How to add trailer record at the end of the flat file in the unix ksh shell scripting?

Hi, How to add trailer record at the end of the flat file in the unix ksh shell scripting can you please let me know the procedure Regards Srikanth (3 Replies)
Discussion started by: srikanth_sagi
3 Replies

6. Shell Programming and Scripting

help with ksh shell scripting

I want to run a script that checks the env to see if I'm in a test or prod environment. From the command line I enter echo $host and it returns host name and I can tell by the name if I'm in test or prod. When I run the command from a script I get "not found" What's wrong with the script? if ... (2 Replies)
Discussion started by: Bperl1967
2 Replies

7. Shell Programming and Scripting

Solaris KSH shell script to copy all lines from one file to another

Hello, more of a windows wscript guy. However I took a new position that requires me to support some solaris servers. So... issue is that I need to copy all lines from a file to a temporary file and then copy them back into the original file starting at line 1. Reason I need to do this is... (5 Replies)
Discussion started by: ZigZaggin
5 Replies

8. Shell Programming and Scripting

Help needed - ksh shell scripting

Hi all, i m new to Unix shell scripting(ksh) i have a requirement, can anyone help me out in this.. spec: i need to move all the files landing in "X" directory to "Y" directory automatically everyday at a particular time.. (5 Replies)
Discussion started by: subbu
5 Replies

9. Shell Programming and Scripting

file handling with ksh scripting

how can i write content of a variable to a file? how can i read standard output into a variable? (1 Reply)
Discussion started by: gfhgfnhhn
1 Replies
Login or Register to Ask a Question