LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2013, 11:02 PM   #1
SpecterWoodland
LQ Newbie
 
Registered: Nov 2013
Posts: 1

Rep: Reputation: Disabled
Writing my first ksh script


Hello everyone, my name's Chris; I'm a newbie obviously

I'm writing a shell script that must copy a single file (sampletext) to multiple directories (folder1, folder2) ; my normal linux go to guy hasn't replied to an email for a while...

So far what i've done -- I created a directory to keep my scripts in, 2 directories I want my file to be copied to, and the file to be copied in a 3rd directory.

The parameters for the script are as follows:
1. The shell script must run as either a ksh or bash shell script.
2. If no parameters are given to the ‘copyall’ then the shell must print/echo a usage message explaining what is required to execute the shell
3. The first parameter of the shell script must be a file and it must exist. It must also be readable. If it is not, the shell script should exit with a status of 99.
4. If the shell script executed correctly it should exit with a status of ‘0’.
5. Under no circumstances should the file /tmp/copyall be overwritten; you add information to the file at the end.
6. Use the ‘echo’ command rather than the built-in ‘print’ command.

8. All parameters after the first one must be directory targets, must be writable, and must exist. If any targets fail these checks print an appropriate error message and exit with a status of 99.
9. When the shell script is run it must not produce any warning or error messages from the script interpreter.

11. The shell script is not designed to be interactive; do not ask the user for any information.


so i have: /home/text-file/sampletext <----the file to be copied
to /home/folder1 and to /home/folder2

Here's what I have so far:
#!/usr/bin/ksh

# This copy script was written by Joe Schmoe on November 5, 2013.
# This script's purpose is to copy single files to multiple directories.

for file in /home/a0699761/text-file/sampletext
do
cp sampletext ${path} ${path}

done
exit0


Thanks for any help, I've only been using linux for 2 months :-/
 
Old 11-06-2013, 02:24 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,767

Rep: Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886
you would need to read the man page of cp, it cannot copy one file into several directories, it can have only one target.
So you need to use two copy commands to achieve your goal.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding KSh script bhargava.konduru Programming 1 07-25-2011 09:18 AM
Convert ksh script into bsh script trouble dan-e Linux - Newbie 1 05-09-2011 02:11 AM
Ksh Script Help sharathkv25 Programming 10 02-02-2007 11:28 AM
help w/ksh script ShaqDiesel Programming 2 01-12-2007 03:04 PM
KSH script AquamaN Programming 2 12-08-2003 12:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration