LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-07-2009, 10:42 AM   #16
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31

If I want to appears a message when this script is done what I have to put?

echo(bla bla bla Backup finished!)

Is that ok?

Dont I have to use ; after every line as in php?
What kind of language can I use. C++? Or only bash command script language?
 
Old 09-07-2009, 10:49 AM   #17
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
If a cron job writes anything to stdout or stderr, cron has nowhere to put the output and will suspend the job (possibly including the stdout or stderr in the informative email, I'm not sure). Better
Code:
echo(bla bla bla Backup finished!) >> <some backup log file name>
EDIT:

The ( ) will cause bash to run bla as a command in a sub-shell. I should have suggested
Code:
echo 'bla bla bla Backup finished!' >> <some backup log file name>

Last edited by catkin; 09-07-2009 at 10:59 AM.
 
Old 09-07-2009, 10:50 AM   #18
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
echo blablablabla

Quote:
Dont I have to use ; after every line as in php?
no
Quote:
What kind of language can I use. C++? Or only bash command script language?
in a bash script bash command script language
or use c++ scripting
http://en.wikipedia.org/wiki/C%2B%2B
http://en.wikipedia.org/wiki/Bash

http://tldp.org/LDP/abs/html/
 
Old 09-07-2009, 10:58 AM   #19
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
There is not diference how I do the script. I can do it with c++ or bash command script language and double click on the file, execute and its runs?
And every script can be execute with crontab, right?
 
Old 09-07-2009, 11:00 AM   #20
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
And every script can be execute with crontab, right?
yes
 
Old 09-07-2009, 11:01 AM   #21
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by miros84 View Post
What kind of language can I use. C++? Or only bash command script language?
cron will run any type of executable that can be run from the command line, including compiled C++.
 
Old 09-07-2009, 11:06 AM   #22
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
Thank you very much for your answars. Now I will learn bash script langage and I will create some script.
 
Old 09-07-2009, 11:12 AM   #23
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by miros84 View Post
There is not diference how I do the script. I can do it with c++ or bash command script language and double click on the file, execute and its runs?
And every script can be execute with crontab, right?
"Script" is not precisely defined but is normally used to refer to interpreted languages including shellscript, awk and PERL. C++ is compiled into a binary executable.

Double clicking on a file suggests running it from a GUI file manager. I'm no expert on how file managers run files but it goes something like this.

The file manager looks at the first few bytes of the file. Scripts begin with #!<language processor file name> <arguments>. In that case the file manager starts the language processor (for example bash) and lets it execute the script. In other cases, the file manager reads a "magic number" from the file which tells it what sort of file it is. In the case of a binary executable the file manager starts a process running the file. In the case of something else, such as a JPEG, the file manager starts the appropriate program and lets it do whatever with the file.

The *n*x "type" command does something similar to the file manager but displays the information in human readable form.
 
Old 09-07-2009, 08:55 PM   #24
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,863

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
BTW
Code:
#! /bin/bash
is wrong. Do not leave a space between '#!' and '/bin/bash'
Also, Perl isn't interpreted, it's 'compiled on the fly', so its about 80% or 90% as quick as C, all other things being equal.
http://www.perl.com/doc/FMTEYEWTK/comp-vs-interp.html
 
Old 09-08-2009, 04:37 AM   #25
miros84
Member
 
Registered: Aug 2009
Location: Spain
Distribution: Debian stable, squeeze
Posts: 501

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by chrism01 View Post
BTW
Code:
#! /bin/bash
is wrong. Do not leave a space between '#!' and '/bin/bash'
Also, Perl isn't interpreted, it's 'compiled on the fly', so its about 80% or 90% as quick as C, all other things being equal.
http://www.perl.com/doc/FMTEYEWTK/comp-vs-interp.html

So, I have to write my scripts only with bash program language?
And If I write some script with c++ or Perl, then it must be compiled and then execute it, right?
 
Old 09-08-2009, 06:26 AM   #26
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by miros84 View Post
So, I have to write my scripts only with bash program language?
And If I write some script with c++ or Perl, then it must be compiled and then execute it, right?
C++ must be compiled. You can treat PERL as if it were a script; the PERL executable compiles the script before executing it.
 
Old 09-08-2009, 06:44 AM   #27
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by chrism01 View Post
BTW
Code:
#! /bin/bash
is wrong. Do not leave a space between '#!' and '/bin/bash'
Thanks for the "heads up", chrism01. According to the GNU Bash Reference, section Shell Scripts, the space should be present. I routinely do not use the space, in line with your comment. I guess it is optional. Do you know how to test it? In other words, is there any way from within a running bash script to determine what the value of <path-to-shell> was in #!<path-to-shell>. I think there is a way but I cannot find it.
 
  


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
linux crontab vs unix crontab ytd Linux - General 2 08-09-2009 05:07 AM
crontab doesn't works heathcliffz Linux - Server 10 07-05-2007 06:19 AM
Shell pgm works fine in command line but not in Crontab oracledba_raja Linux - General 2 11-24-2006 12:14 AM
shell script works form command line but not form crontab saifee General 1 10-14-2004 10:27 AM
crontab doesnt works with all jobs. pxes351 Linux - Newbie 2 05-10-2004 01:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:42 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