LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Simple script (https://www.linuxquestions.org/questions/linux-newbie-8/simple-script-4175547245/)

akashi 07-04-2015 10:19 PM

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.

LinBox2013 07-04-2015 11:19 PM

Just write a script and add a wait state.

It looks rather simple to me.

First command
wait
second command
wait

And so on.

Keith Hedger 07-05-2015 06:18 AM

you dont need to add a 'waitstate' the next command will not start until the current command terminates.

LinBox2013 07-05-2015 06:22 AM

Quote:

Originally Posted by Keith Hedger (Post 5387397)
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 :D.

Keith Hedger 07-05-2015 03:57 PM

We all suffer from mushy brain syndrome sometimes :)

akashi 07-05-2015 05:43 PM

How do I write the script?

Can someone please give an example.

Thanks.

Keith Hedger 07-05-2015 05:53 PM

this is very basic scripting, please show what you have tried yourself, we are not going to write this script for you.

TB0ne 07-05-2015 05:54 PM

Quote:

Originally Posted by akashi (Post 5387585)
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.

joe_2000 07-06-2015 04:18 PM

Quote:

Originally Posted by akashi (Post 5387585)
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

akashi 07-06-2015 06:26 PM

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:


Keith Hedger 07-06-2015 06:32 PM

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.

Aia 07-06-2015 07:57 PM

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

chrism01 07-07-2015 05:09 AM

... 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.

akashi 07-07-2015 10:28 AM

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 :D

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

Thanks everyone for your contributions.

joe_2000 07-07-2015 02:52 PM

Quote:

Originally Posted by akashi (Post 5388113)
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.


All times are GMT -5. The time now is 11:39 PM.