Newb writing his first shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Newb writing his first shell script
# 1  
Old 03-01-2011
Newb writing his first shell script

Hey!

This is my first post on this forum, nice to meet ya!

I've been using Linux for a good few years, I grew up using DOS and a few similar CLI-based OS's so I'm fairly okay with navigating my way around the terminal. Recently I decided I wanted to become a sysadmin so I've been teaching myself Unix from this huge book (still only 60~ pages in, mind).

This is my first time trying to write a shell script and I've already become stumped. I want to write a simple command that would copy a file I choose to my Dropbox folder. This is what I've written so far:

Code:
#
# My first script, designed to copy a file to my Dropbox!
#

clear
echo "Copying file to Dropbox."
cp [file] /usr/Richard/Dropbox/Copied_Stuff
echo "Copying completed."
exit 0

Obviously, [file] is meant to be the file I want to copy over but I can't for the life of me figure out what the command is to make it what file I want.

I know if it was just a simple command it would be:
Code:
cp helloworld.txt /usr/Richard/Dropbox/Copied_Stuff

But what if I want to make my own command (say call it "dbox") so it's like:
Code:
dbox helloworld.txt

Any help for this newb is appreciated.Smilie
# 2  
Old 03-01-2011
echo "Please Enter File if copy"
read FILE

#check if file exists first
if [ -e ${FILE} ]; then
cp ${FILE} /usr/Richard/Dropbox/Copied_Stuff
fi


Is this what your after?
This User Gave Thanks to robfwauk For This Post:
# 3  
Old 03-01-2011
Quote:
Originally Posted by robfwauk
echo "Please Enter File if copy"
read FILE

#check if file exists first
if [ -e ${FILE} ]; then
cp ${FILE} /usr/Richard/Dropbox/Copied_Stuff
fi


Is this what your after?
Thanks, sir! I've fiddled with it a bit to make it echo a confirmation/failure but it works like a charm! Thanks!

Would you mind helping me install it as a command? I can get it to run if I'm in the dir the script is in but I want to be able to use it anywhere without having to type ./dbox.sh
# 4  
Old 03-01-2011
Im guessing the easiest way would be to put the dbox.sh script in /usr/bin

Assuming that the file is always being copied to the same location your script would then do something like this..

run script -> dbox helloworld.txt (without the ./)

script->

cp ${1} /usr/Richard/Dropbox/Copied_Stuff
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (4 Replies)
Discussion started by: ShiGua
4 Replies

2. Shell Programming and Scripting

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (2 Replies)
Discussion started by: ShiGua
2 Replies

3. Shell Programming and Scripting

Writing a shell script

Hi I have two files a.log and b.log . i need to append a.log and b.log so that at the end of first line in a.log i need the append the data of first line from b.log and end of the second line in a.log i need to append the data of second line from b.log and so on up to the end of the file can... (3 Replies)
Discussion started by: lalu
3 Replies

4. UNIX and Linux Applications

Need help in writing shell script

I have written a shell script and when i ran the script,for some point of time it is asking to press enter key manually using keyboard.So i need it the enter key in shell itself. ex : in my shell script,i used the command ssh-keygen -t rsa so it asks the enter 3 times. can you please let me know... (3 Replies)
Discussion started by: lkeswar
3 Replies

5. Shell Programming and Scripting

Need help in writing the shell script

Can anyone please help me in writing a shell script that would check if a particular user(xyz) has logged in, and if yes, the audit daemon needs to be started. When the user logs off the dameon needs to shutdown , and the report needs to be e-mailed to a set of users. (12 Replies)
Discussion started by: ggayathri
12 Replies

6. Shell Programming and Scripting

Writing shell script

Hi, I am a new for shell script. i need to write script using the following commands cd /usres/test # create directory mkdir temp+DATE( i need to append date ) #moving files from one directory to this directory(we need to check total files in source and taget) cd /users/sample ... (2 Replies)
Discussion started by: bmkreddy
2 Replies

7. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

8. UNIX for Dummies Questions & Answers

Writing a shell Script

How to write a shell script file to read 5 numbers using a while loop. Finding the average, maximum and minumum for the numbers. Any help would be great. (1 Reply)
Discussion started by: Chin
1 Replies

9. Shell Programming and Scripting

Need help with writing shell script

I have the following output. I want to write a script to check for 1. waits > 0 on all rowsand Ratio > .0. if true then send email. ========================= ROLLBACK SEGMENT CONTENTION ========================= If any ratio is > .01 then more rollback segments are needed NAME ... (1 Reply)
Discussion started by: jigarlakhani
1 Replies

10. Shell Programming and Scripting

newb shell question

I know this is a total begginer question but what is wrong with this picture. My loop wont loop, it just drops me back to the prompt and gives the error "unary operator expected". Any help would be appreciated. here it is, #!/bin/sh selection= while do cat << MENU 1)List files in... (2 Replies)
Discussion started by: Fokus
2 Replies
Login or Register to Ask a Question