Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Verification on shell script

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-20-2013
nimafire nimafire is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 18 April 2018, 1:40 PM EDT
Posts: 60
Thanks: 17
Thanked 0 Times in 0 Posts
Verification on shell script

hello i have writing a shell script to download and run some packages
the only way that i use to verify download pack is , limit users ip to download from main server, if wget can download file (verified) then script run by execute it sh pack76.sh
else show and error

(stupid solution ha?)

Code:
if [ $answer = y ]; then
	cd $INSTALLDIR
	wget $MIRROR/pack76.sh
	if [ -f $INSTALLDIR/pack76.sh ]
	then
		sh pack76.sh
	else
		echo -e "$RED you dont have permition to download $RESET"
	fi
fi

any idea ?
Sponsored Links
    #2  
Old 09-20-2013
gacanepa gacanepa is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 10 January 2017, 8:33 PM EST
Location: Villa Mercedes, San Luis, Argentina
Posts: 176
Thanks: 24
Thanked 27 Times in 23 Posts
I am not sure I understand what you mean by
Quote:
verify download pack
What are you trying to download and from where?
Also, I see a few problems with your code, for example:
Code:
$answer = y

is an assignment statement and won't return a boolean value (True or False), which is what you seem to need here.
Second, here
Code:
	if [ -f $INSTALLDIR/pack76.sh ]
	then
		sh pack76.sh
	else
		echo -e "$RED you dont have permition to download $RESET"
	fi

You are checking for the existence of the file pack76.sh (what is this supposed to do and what are its contents, by the way?) and if it doesn't exist you are echoing a message saying that the user doesn't have permission to perform the download operation - I believe you should have checked for permissions along with existence.
But I'm afraid I can't tell for sure just by looking at the code snippet you included in your post.
Please provide more details and a concise explanation of what you're trying to accomplish, along with the source code that you're already tried and any problems you may have encountered in the process.
Sponsored Links
    #3  
Old 09-20-2013
nimafire nimafire is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 18 April 2018, 1:40 PM EDT
Posts: 60
Thanks: 17
Thanked 0 Times in 0 Posts
tnq gacanepa

i have copy part of my code that need to open this topic,
ok let me explain how i have verify :
i have add .htaccess on $mirror so if untruest machine send request to download package,only allow ip which add on .htaccess will permit to download,
i will add ips manually.

then if command will check, is file download and exist or not
if wget coud download file (allow) yes, it will open package and compile it, else, it will show warning
main part of verification is :

Code:
wget $MIRROR/pack76.sh
	if [ -f $INSTALLDIR/pack76.sh ]
	then
		sh pack76.sh
	else
		echo -e "$RED you dont have permition to download $RESET"
	fi

    #4  
Old 09-20-2013
gacanepa gacanepa is offline
Registered User
 
Join Date: Jun 2013
Last Activity: 10 January 2017, 8:33 PM EST
Location: Villa Mercedes, San Luis, Argentina
Posts: 176
Thanks: 24
Thanked 27 Times in 23 Posts
I insist that checking the existence of a file is not the best way to allow or deny its execution.
What I would do is wget the file, then if that command completed successfully I'd start the download operation, otherwise I'd show the error message, more like so:
Code:
wget $MIRROR/pack76.sh
	if [ $? == 0 ]
	then
		sh pack76.sh
	else
		echo -e "$RED The download cannot be performed $RESET"
	fi

Hope it helps.
The Following User Says Thank You to gacanepa For This Useful Post:
nimafire (09-20-2013)
Sponsored Links
    #5  
Old 09-20-2013
vbe's Unix or Linux Image
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 16 July 2018, 9:56 AM EDT
Location: Switzerland - GE
Posts: 6,550
Thanks: 311
Thanked 564 Times in 526 Posts
I get the point of the thread owner..., what I dont understand is since he knows who are allowed ( IP list...) why not test if you are allowed to download?
The Following User Says Thank You to vbe For This Useful Post:
gacanepa (09-20-2013)
Sponsored Links
    #6  
Old 09-20-2013
nimafire nimafire is offline
Registered User
 
Join Date: Aug 2013
Last Activity: 18 April 2018, 1:40 PM EDT
Posts: 60
Thanks: 17
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by vbe View Post
I get the point of the thread owner..., what I dont understand is since he knows who are allowed ( IP list...) why not test if you are allowed to download?
mm i want to publish my script so i need verification method to know who use this script
i have not find any solution to encode-decode shell scripting so i use ip restriction by allow and deny

---------- Post updated at 02:18 PM ---------- Previous update was at 02:12 PM ----------

Quote:
Originally Posted by gacanepa View Post
I insist that checking the existence of a file is not the best way to allow or deny its execution.
What I would do is wget the file, then if that command completed successfully I'd start the download operation, otherwise I'd show the error message, more like so:
Code:
wget $MIRROR/pack76.sh
	if [ $? == 0 ]
	then
		sh pack76.sh
	else
		echo -e "$RED The download cannot be performed $RESET"
	fi

Hope it helps.
good idea
so shell scripting do not have any protection like i need?
so what shell programmer do?
Sponsored Links
    #7  
Old 09-20-2013
MadeInGermany MadeInGermany is offline Forum Staff  
Moderator
 
Join Date: May 2012
Last Activity: 18 July 2018, 4:13 PM EDT
Location: Simplicity
Posts: 4,156
Thanks: 365
Thanked 1,419 Times in 1,275 Posts
Code:
[ $answer = y ]

is not an assignment, and works with all sh-type shells.
But eventually give a test syntax error when $answer is empty or multi-word. Safe is
Code:
[ "$answer" = y ]

While
Code:
[ "$answer" == y ]

is an extension of the test command - not portable.
Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script Verification k33k00 Shell Programming and Scripting 1 04-07-2012 07:32 AM
Script for verification of Data corruption manish_tcs_hp Shell Programming and Scripting 4 12-07-2010 08:14 PM
Email address verification script Ramdas Shell Programming and Scripting 4 01-15-2007 01:51 AM
Verification of a script already running - where to do it miwinter UNIX for Dummies Questions & Answers 2 08-07-2006 10:32 AM
verification? sheranjem UNIX for Dummies Questions & Answers 3 06-06-2005 01:08 PM



All times are GMT -4. The time now is 06:13 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?