LinuxQuestions.org
Review your favorite Linux distribution.
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 06-08-2014, 08:33 AM   #1
kunalks
Member
 
Registered: Dec 2013
Posts: 53

Rep: Reputation: Disabled
(IF else statement in linux bash sheel!)


Hallo GUys
I am trying to run this script and than i am having some problem in it

Can someone please help me to solve it out
Script code

if ( /bin/cp -rf "$LOCATION/$FILE" /mnt/smb/"$DESTINATION" > /dev/null ) ; then
echo "File is being copied"
I think i am doing some mistake here(Underline part.)

else
a=$( df -h /mnt/smb | tail -n +2 | tr -s ' ' | tr '%' ' ' | cut -d ' ' -f 5)
echo "drive space $a"
if [[ $a -gt 80 ]]; then
cat /etc/diskspace/text.txt | sendmail test@gmail.com
fi

can someone has solution about it? I need to stop the further operation if coping of file is already running!
Every hint would be appriciable


thanks
 
Old 06-08-2014, 08:39 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
What is your 'problem'?
Are you getting an error?

You will need to provide more information if you wish assistance.

Currently my only suggestion to help you debug is to place set -xv at the start of the script and check the output it delivers.
 
Old 06-09-2014, 09:32 PM   #3
kunalks
Member
 
Registered: Dec 2013
Posts: 53

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
What is your 'problem'?
Are you getting an error?

You will need to provide more information if you wish assistance.

Currently my only suggestion to help you debug is to place set -xv at the start of the script and check the output it delivers.

LOGFILE="/var/log/vpnc/filetransfer.log"

#Grab the Drivespace

if ( /bin/cp -rf "$LOCATION/$FILE" /mnt/smb/"$DESTINATION" 2>> $LOGFILE > /dev/null ); then
echo -n 'date' >> $LOGFILE && echo "Files are being copied." >> $LOGFILE

else
# check the drive space.
a=$(df -h /mnt/smb | tail -n +3 | tr -s ' ' | tr '%' ' ' | cut -d ' ' -f 5)
echo $a

if [[ $a -ge 54 ]]; then
cat /etc/diskspace/text.txt | sendmail test@gmail.com
fi


Here is the part of my script and underline part of this script is added now and this is making error..
And here are some error which i took it from logfile.
Error FROM LOGFILE
/bin/cp: cannot create symbolic link `/mnt/smb/etc/rc4.d': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/favicon.png': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/redhat-release': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/system-release': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/rc6.d': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/ssl/certs': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/sysconfig/network-scripts/ifup': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/sysconfig/network-scripts/ifup-isdn': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/sysconfig/network-scripts/ifdown-isdn': Operation not supported
/bin/cp: cannot create symbolic link `/mnt/smb/etc/sysconfig/network-scripts/ifdown': Operation not supported
 
Old 06-09-2014, 09:33 PM   #4
kunalks
Member
 
Registered: Dec 2013
Posts: 53

Original Poster
Rep: Reputation: Disabled
i ONLY HAVE THIS ERROR WHEN I USE UNDERLINE PART IN THE SCRIPT:
 
Old 06-09-2014, 10:52 PM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,330
Blog Entries: 1

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
insert an echo after each line with unique text to see if you're going where you think you should go? the if with the () and cp in it is questionable though. The true / false values can differ between apps and scripting interpreter. Sometimes 1 for true, 0 for false. Sometimes the inverse. In either case things to be executed should be encapsulated in $(), the the `` of newer versions of things.
 
Old 06-10-2014, 01:24 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Actually, I would get rid of the brackets all together as 'if' is quite capable of reading the return status of commands.

We also have no idea what is in or how variables are being set, but the error output seems quite clear on the fact that you probably do not have permission to perform the copy task you are trying to implement.

As stated in my first post, try placing the following at the start of the script (or at least prior to the concerned area:
Code:
set -xv
This will provide additional output to advise what variables have been set to prior to commands being used on them.

Lastly, please use [code][/code] tags around data or code to make it more legible.
 
Old 06-10-2014, 01:39 AM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,133

Rep: Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273Reputation: 2273
what kind of filesystem was mounted on /mnt/smb (and how?)
 
Old 06-17-2014, 03:49 AM   #8
kunalks
Member
 
Registered: Dec 2013
Posts: 53

Original Poster
Rep: Reputation: Disabled
if ( ps -ef | grep -v grep | grep -v vpnc_ondemand | grep -v less | grep vpnc > /dev/null ) ; then
echo "Shell script is already running there for we make exit".
exit
else
echo "Run the other par of script."
fi


Guys this was my code and solution for my problem. i just made codition if the scipt is running or not if yes then terminate the whole script.

Thanks for your helps.
 
Old 06-17-2014, 04:45 AM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Please use tags around data or code to make it more legible.

Glad you found a solution, although I am not quite sure how this solved the original problem.
You may also wish to investigate the pgrep command so you can be more succinct with what you are looking for.
 
  


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
Bash for statement Linux_Kidd Linux - General 10 11-14-2012 11:30 AM
How to get some bash scripts into a simple bash script with some echo and if statement. y0_gesh Programming 3 03-01-2012 10:46 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM
Bash: Print usage statement & exit; otherwise continue using Bash shorthand operators stefanlasiewski Programming 9 02-07-2006 06:20 PM


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