Sponsored Content
Full Discussion: Bash Shell script--need help
Top Forums Shell Programming and Scripting Bash Shell script--need help Post 302340880 by kshji on Tuesday 4th of August 2009 02:28:13 PM
Old 08-04-2009
I use ksh in my script, this is one reason - builtin float calculation support.
Code:
#!/bin/ksh
# LANG set to C = no locale delimeter , / . and so on
LANG=C
echo -n "what is your salary ?"
read salary
DA=0.4
(( Deduction=DA * $salary  ))
rent=0.2
(( rentdeduct=rent * salary  ))
(( grossalary=salary - Deduction + rentdeduct  ))
echo "$grossalary"
# or better for output
printf "%.2f\n" "$grossalary"

Or if use bash, then use bc "calculator":
Code:
value=$( echo "$num1 * $num2" | bc )

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

need help with bash shell script

Hi guys! I have just started with shell programming!! I am having pronblem with variable subsitutuion. when i do egrep "*" marks this will give me the pattern match. but how can i catch the output of that result in a variable. if i say result = egrep "*" marks it gives me syntax... (2 Replies)
Discussion started by: vmtailor
2 Replies

2. UNIX for Dummies Questions & Answers

Bash shell script

Hi Guys, I am trying to alter a script for my company. I need the start of it to go something like this. User is asked to input 8 numbers 8 numbers are written to a txt file ***** ***** ***** txt file is read ***** ***** The text file gets read in between other files represented by... (2 Replies)
Discussion started by: outthere_3
2 Replies

3. Shell Programming and Scripting

Bash shell script- help

I need to invoke a program on remote server using ssh in a shell script. In addition i would like to capture date/time and if there is any errors , then script should write to log file. can someone please help me out? (1 Reply)
Discussion started by: sam101
1 Replies

4. Shell Programming and Scripting

Help with bash shell script

Hi, I have a file in which records contains non ascii characters. The records are comma delimited and quoted. The non ascii characters are found in a particular column. Example records "YY","AK000021","Ã","IO","PP" "Y1","AK000022","Ã","PO","PP" "Y2","AK000022","Ã","PO","PP" I need to... (2 Replies)
Discussion started by: akshu.agni
2 Replies

5. Shell Programming and Scripting

Bash Shell Script

HELP!My program ends after entering one choice---need help making it take multiple inputs,instead of terminating after displaying just one #!/bin/bash# Crude address databaseclear # Clear the screen.echo " Contact List"echo " ------- ----"echo "Choose one of the following... (6 Replies)
Discussion started by: help123
6 Replies

6. Shell Programming and Scripting

Bash shell script to check if script itself is running

hi guys we've had nagios spewing false alarm (for the umpteenth time) and finally the customer had enough so they're starting to question nagios. we had the check interval increased from 5 minutes to 2 minutes, but that's just temporary solution. I'm thinking of implementing a script on the... (8 Replies)
Discussion started by: hedkandi
8 Replies

7. Shell Programming and Scripting

Need help with bash shell script

I need to create digit day script that takes a single numeric argument and then it should print out the day of the week using the number modulo 7 formula e.g: 0 - Sunday 6- Saturday 131 - Friday I am fairly new to unix so I don't know how to use the number modulo 7 formula. Does the script need... (3 Replies)
Discussion started by: lukefrost96
3 Replies

8. Shell Programming and Scripting

Help with Bash shell script

Hi All, I have a script which as below #!/bin/bash for i in `cat servers` do ssh uname@$i "df -t xfs --total | grep total"; done > out.txtOutput as below -------------- total 140583991104 118622795524 21961195580 85% - total 140583991104 112888595524 27695395580 ... (4 Replies)
Discussion started by: npk
4 Replies

9. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s... (5 Replies)
Discussion started by: da1
5 Replies

10. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies
Apache2::SiteControl::PermissionManager(3pm)		User Contributed Perl Documentation	      Apache2::SiteControl::PermissionManager(3pm)

NAME
Apache2::SiteControl::PermissionManager - Rule-based permission management SYNOPSIS
use Apache2::SiteControl::PermissionManager; $manager = new Apache2::SiteControl::PermissionManager(); $rule1 = new SomeSubclassOfSiteControl(); $manager->addRule($rule1); ... $user = new SomeUserTypeYouDefineThatMakesSenseToRules; if($manager->can($user, $action, $resource)) { # OK to do action } # For example if($manager->can($user, "read", "/etc/shadow")) { open DATA, "</etc/shadow"; ... } DESCRIPTION
This module implements a user capabilities API. The basic idea is that you have a set of users and a set of things that can be done in a system. In the code of the system itself, you want to surround sensitive operations with code that determines if the current user is allowed to do that operation. This module attempts to make such a system possible, and easily extensible. The module requires that you write implementations of rules for you system that are subclasses of Apache2::SiteControl::Rule. The rules can be written to use any data types, which are abstractly known as "users", "actions", and "resources." A user is some object that your applications uses to identify the person operating the program. The expectation is that at some point the application authenticated the user and obtained their identity, and the rest of the application is merely applying a ruleset to determine what that user is allowed to do. In the context of the SiteControl system, this user is a Apache2::SiteControl::User or subclass thereof. An action can be any data type (i.e. simply a string). Again, it is really up to the code of the rules (which are primarily written by you) to determine what is valid. The overall usage of this package is as follows: 1. Decide how you want to represent a user. (i.e. Apache2::SiteControl::User) 2. Decide the critical sections of your code that need to be protected, and decide what to do if the user doesn't pass muster. For example if a screen should just hide fields, then the application code needs to reflect that. 3. Create a permission manager instance for your application. Typically use a singleton pattern (there need be only one manager). In the SiteControl system, this is done by a ManagerFactory that you write. 4. Surround sensitive sections of code with something like: if($manager->can($user, "view salary", $payrollRecord)) { # show salary fields } else # hide salary fields } 5. Create rules that spell out the behavior you want and add them to your application's permission manager. The basic idea is that a rule can grant permission, or deny it. If it neither grants or denies, then the manager will take the safe route and say that the action cannot be taken. Part of the code for the rule for protecting salaries might look like: package SalaryViewRule; use Apache2::SiteControl::Rule; use Apache2::SiteControl::User; use base qw(Apache2::SiteControl::Rule); sub grants { $this = shift; $user = shift; $action = shift; $resource = shift; # Do not grant on requests we don't understand. return 0 if(!$user->isa("Apache2::SiteControl::User") || !$this->isa("Apache2::SiteControl::Rule")); if($action eq "view salary" && $resource->isa("Payroll::Record")) { if($user->getUsername() eq $resource->getEmployeeName()) { return "user can view their own salary"; } } return 0; } Then in your subclass of ManagerFactory: use SalaryViewRule; ... $viewRule = new SalaryViewRule; $manager->addRule($viewRule); METHODS
can(user, action verb, resource) This is the primary method of the PermissionManager. It asks if the specified user can do the specified action on the specified resource. For example, $manager->can($user, "eat", "cake"); would return true if the user is allowed to eat cake. Note that this gives you quite a bit of flexibility, but at the expense of strong type safety. It is suggested that all of your rules do type checking to insure that a rule is properly applied. SEE ALSO
Apache2::SiteControl::Rule, Apache::SiteControl::ManagerFactory, Apache2::SiteControl::UserFactory, Apache::SiteControl AUTHOR
This module was written by Tony Kay, <tkay@uoregon.edu>. COPYRIGHT AND LICENSE
perl v5.14.2 2006-03-17 Apache2::SiteControl::PermissionManager(3pm)
All times are GMT -4. The time now is 11:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy