LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 07-04-2015, 10:19 PM   #1
akashi
LQ Newbie
 
Registered: Dec 2010
Posts: 20

Rep: Reputation: 0
Simple script


Can someone please help me write a script that will perform the following commands together:

Code:
tar zcvf aria2.tar.gz /etc/aria2.conf /etc/init.d/aria2
tar zcvf minidlna.tar.gz /etc/minidlna.conf /etc/init.d/minidlna
tar zcvf nzbdrone.tar.gz /root/.config/NzbDrone /etc/init.d/nzbdrone
tar zcvf nzbget.tar.gz /etc/nzbget.conf /etc/init.d/nzbget
tar zcvf openvpn.tar.gz /etc/openvpn/server.conf /etc/init.d/openvpn
tar zcvf vsftpd.tar.gz /etc/vsftpd.conf /etc/init.d/vsftpd
If I run these commands one at a time, they execute without any errors.

Thanks in advance.
 
Old 07-04-2015, 11:19 PM   #2
LinBox2013
Member
 
Registered: Sep 2013
Location: Southern Kentucky
Distribution: Arch
Posts: 119

Rep: Reputation: 45
Just write a script and add a wait state.

It looks rather simple to me.

First command
wait
second command
wait

And so on.
 
Old 07-05-2015, 06:18 AM   #3
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
you dont need to add a 'waitstate' the next command will not start until the current command terminates.
 
Old 07-05-2015, 06:22 AM   #4
LinBox2013
Member
 
Registered: Sep 2013
Location: Southern Kentucky
Distribution: Arch
Posts: 119

Rep: Reputation: 45
Quote:
Originally Posted by Keith Hedger View Post
you dont need to add a 'waitstate' the next command will not start until the current command terminates.
Your right.

Don't know what I was thinking. I will blame late .
 
Old 07-05-2015, 03:57 PM   #5
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
We all suffer from mushy brain syndrome sometimes
 
Old 07-05-2015, 05:43 PM   #6
akashi
LQ Newbie
 
Registered: Dec 2010
Posts: 20

Original Poster
Rep: Reputation: 0
How do I write the script?

Can someone please give an example.

Thanks.
 
Old 07-05-2015, 05:53 PM   #7
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
this is very basic scripting, please show what you have tried yourself, we are not going to write this script for you.
 
1 members found this post helpful.
Old 07-05-2015, 05:54 PM   #8
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by akashi View Post
How do I write the script?
Can someone please give an example.
First, there are THOUSANDS of very easily-found scripting examples you could find with a brief Google search, in less time than it took you to post this. There is even one in my posting signature.

Also, you have already written the script...put those commands in a file...make it executable. There is your script.
 
Old 07-06-2015, 04:18 PM   #9
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by akashi View Post
How do I write the script?

Can someone please give an example.

Thanks.
Code:
#!/bin/sh
tar zcvf aria2.tar.gz /etc/aria2.conf /etc/init.d/aria2
tar zcvf minidlna.tar.gz /etc/minidlna.conf /etc/init.d/minidlna
tar zcvf nzbdrone.tar.gz /root/.config/NzbDrone /etc/init.d/nzbdrone
tar zcvf nzbget.tar.gz /etc/nzbget.conf /etc/init.d/nzbget
tar zcvf openvpn.tar.gz /etc/openvpn/server.conf /etc/init.d/openvpn
tar zcvf vsftpd.tar.gz /etc/vsftpd.conf /etc/init.d/vsftpd
...and you're done
 
1 members found this post helpful.
Old 07-06-2015, 06:26 PM   #10
akashi
LQ Newbie
 
Registered: Dec 2010
Posts: 20

Original Poster
Rep: Reputation: 0
Thank you joe_2000 for the example. I already tried this before I asked for help. I always receive this error message at the end:

Code:
tar: \r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
tar: Removing leading `/' from member names
/etc/nzbget.conf
/etc/init.d/nzbget
tar: \r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
tar: Removing leading `/' from member names
/etc/openvpn/server.conf
/etc/init.d/openvpn
tar: \r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
tar: Removing leading `/' from member names
/etc/vsftpd.conf
tar: /etc/init.d/vsftpd\r: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
: not found.sh: 8: backup.apps.sh:
: not found.sh: 9: backup.apps.sh:
 
Old 07-06-2015, 06:32 PM   #11
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,150

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
If you had posted this as you were asked to do earlier your problem could have been solved.
Looks like you dont have linux line endings, the \r is a carriage return and is not used in linux it is used in windows, I assume you have wriiten your script on a windows machine, using somthing like notepad, you need to use linux endings ( \n ) so use a linux text editor, leafpad for example.

Last edited by Keith Hedger; 07-06-2015 at 06:35 PM. Reason: spelling
 
1 members found this post helpful.
Old 07-06-2015, 07:57 PM   #12
Aia
Member
 
Registered: Jun 2006
Posts: 66

Rep: Reputation: 21
Do you see all those \r? That's a carriage return. Usually happens when you move text from a system like Windows to Unix-like.
You need to remove them first.

Code:
sed -e 's/\r$//' file_with_carriage > file_without_carriage
 
1 members found this post helpful.
Old 07-07-2015, 05:09 AM   #13
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
... or just use the std tool dos2unix.

But, as above, if you write the script on Linux in the first place, this will not be an issue.
 
1 members found this post helpful.
Old 07-07-2015, 10:28 AM   #14
akashi
LQ Newbie
 
Registered: Dec 2010
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks Keith Hedger, I wrote it in nano and it is working perfectly now

I previously used Notepad++ on Windows. Didn't think it would cause any problems, learnt something now

I am really enjoying learning a lot about Linux being a long time Windows users.

Thanks everyone for your contributions.
 
Old 07-07-2015, 02:52 PM   #15
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by akashi View Post
Thank you joe_2000 for the example. I already tried this before I asked for help.
If I may recommend: Try and make it a habit to actually include such information in your initial question. When you run into problems, error messages are the most valuable information for people to be able (and willing) to help.

Not only do they prove you actually tried something for yourself but they also provide pointers as to what went wrong.

Furthermore, before even posting a question: When you get error messages, copy and paste them into the search engine of your choice. Chances are that someone has had this problem before you, and the solution is already available on the web.
 
1 members found this post helpful.
  


Reply



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
Need help getting started simple simple shell script dhonnoll78 Programming 6 12-17-2007 05:34 PM
Simple script to wait for another script Maverick1182 Linux - Newbie 4 11-05-2007 03:45 AM
Iptables (with masq) troubleshooting, very simple script attached script and logs. xinu Linux - Networking 13 11-01-2007 04:19 AM
Need help with a simple script shell script WindowBreaker Linux - Software 2 12-15-2005 12:45 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

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

All times are GMT -5. The time now is 07:49 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
Open Source Consulting | Domain Registration