LinuxQuestions.org
Help answer threads with 0 replies.
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 04-27-2011, 02:23 AM   #1
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Rep: Reputation: 12
functions in linux


Hi all

Can i do this with a function?

Code:
test1(){

statresult=`$find $dirpath -type f | $wc -l |$tail -1`
dirsize=`echo $statresult`

if [ $dirsize -gt 0 ]; then
	VAR=`$find $dirpath -name "*.*" -type f -mmin +$time | $wc -l`
	
	if [ $VAR -gt 0 ]; then
		result="Warning"
		exitstatus=$STATE_WARNING
	else
		exitstatus=$STATE_OK
	fi
else
	exitstatus=$STATE_OK
fi

echo you're here

}
if yes, how can i call that?

The problem is that i need to check on lot's of folders and i would like to manage them in one script.
the difficulty is that certain folders need other things to be checked on... So i need several 'function' that all needed to be checked

Thx
 
Old 04-27-2011, 03:27 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
what are you asking? Can that be done in a function? That IS a function...
 
0 members found this post helpful.
Old 04-27-2011, 04:08 AM   #3
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
yes i know, maybe i'm not clear what i WAS trying to ask (i figured it out..)
i wanted to know if you can put commands like IF in a function, because i saw some examples of functions and they only did echoes in it, so i thought that was only possible in a function.

but now i know it

thanks anyways
 
Old 04-27-2011, 04:32 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
No, there is no restriction whatsoever about what can be in a function compared to anywhere else in a bash script.
 
1 members found this post helpful.
Old 04-27-2011, 04:34 AM   #5
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
thx for clearing that one out
 
Old 04-27-2011, 09:13 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by brownie_cookie View Post
Code:
"*.*"
If you're doing that because you're used to "*.*" from Widnows, don't. Linux doesn't have a concept of file extensions, and files may not have them. Just use "*" instead.

Quote:
Originally Posted by brownie_cookie View Post
Code:
echo you're here
That quote will confuse BASH. Do this instead:

Code:
echo "you're here"
 
1 members found this post helpful.
Old 04-27-2011, 09:20 AM   #7
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by MTK358 View Post
If you're doing that because you're used to "*.*" from Widnows, don't. Linux doesn't have a concept of file extensions, and files may not have them. Just use "*" instead.
I'm not used of using that from Windows i just wanted to be sure that everything will be handled, but if you're garanteeing that it will work, i'll change it thanks for the tip

Quote:
Originally Posted by MTK358 View Post
That quote will confuse BASH. Do this instead:

Code:
echo "you're here"
i know normally that was another echo, but i'm from Belgium, so i thought, let's change it to something english (i changed it here, not in my script!)
but thx anyways for taking your time to reply to this
 
Old 04-27-2011, 09:31 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by brownie_cookie View Post
I'm not used of using that from Windows i just wanted to be sure that everything will be handled, but if you're garanteeing that it will work, i'll change it thanks for the tip
"*" catches everything, "*.*" catches everything with a dot in the name.
 
Old 04-27-2011, 09:42 AM   #9
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by MTK358 View Post
"*" catches everything, "*.*" catches everything with a dot in the name.
ok thx it has been changed
 
Old 04-27-2011, 11:22 AM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Is there some reason you do
Code:
statresult=`$find $dirpath -type f | $wc -l |$tail -1`
dirsize=`echo $statresult`

if [ $dirsize -gt 0 ]; then
rather than the simpler version?
Code:
statresult=`$find $dirpath -type f | $wc -l`
if [ $statresult -gt 0 ]; then
Or, is there some special circumstance that you are trying to accomodate?


--- rod.
 
Old 04-28-2011, 02:03 AM   #11
brownie_cookie
Member
 
Registered: Mar 2011
Location: Belgium
Distribution: CentOS release 5.5 (Final), Red Hat Enterprise Linux ES release 4 (Nahant Update 8)
Posts: 416
Blog Entries: 2

Original Poster
Rep: Reputation: 12
Quote:
Originally Posted by theNbomr View Post
Is there some reason you do
Code:
statresult=`$find $dirpath -type f | $wc -l |$tail -1`
dirsize=`echo $statresult`

if [ $dirsize -gt 0 ]; then
rather than the simpler version?
Code:
statresult=`$find $dirpath -type f | $wc -l`
if [ $statresult -gt 0 ]; then
Or, is there some special circumstance that you are trying to accomodate?


--- rod.
I know what you're saying but i got this code from someone and i don't try to mess with it too much
I've noticed it too, but i thought that he did that with a good reason so i let it be
but i understand what you're saying
 
Old 04-28-2011, 09:35 AM   #12
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
And one more thing: the thread is about bash functions, not "Linux functions". You can use any other shell, wih completely different syntax, in Linux.
 
  


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
OSE system call functions to Linux Sytem Call functions required roshantraj30 Linux - General 0 06-08-2009 03:06 AM
LXer: OpenOffice.org Calc functions, part 1: Understanding functions LXer Syndicated Linux News 0 03-31-2007 01:01 PM
Slackpkg: missing something in /usr/libexec/slackpkg/functions.d/dialog-functions.sh michelino Slackware 4 03-20-2007 01:22 PM
Converting php5 socket functions to php3 socket functions mrobertson Programming 0 06-23-2005 10:11 AM
pointers to functions/member functions champ Programming 2 03-28-2003 07:22 PM


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