Sponsored Content
Homework and Emergencies Homework & Coursework Questions changing permissions of a file whos name was passed to 755 Post 302398451 by methyl on Wednesday 24th of February 2010 05:02:46 PM
Old 02-24-2010
Some clues to get you started.

If an executable script called "myscript" was invoked from the command line as
Code:
./myscript myfilename 755

we can save the parameters into named environment variables called say filename from $1 and the permissions parameter (755) from $2.

Code:
filename="$1"
echo "The first parameter is: ${filename}"
perms="$2"
echo "The second parameter is: ${perms}"

If we want to find out the current directory listing for the file myfile we can extend the script by one line. Any line starting with a hash character (#) a comment line and will be ignored by the shell.

Code:
filename="$1"
echo "The first parameter is: ${filename}"
perms="$2"
echo "The second parameter is: ${perms}"
# Directory listing for file called myfile
ls -la "${filename}"

Now we understand script parameters, we can take the saved $2 (now called ${perms} ) and substitute it into a unix chmod command.

Your turn!

Last edited by methyl; 02-24-2010 at 06:16 PM.. Reason: After discussion with colleagues decided to put 755 on the command call to point the way.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

changing file permissions

Use the following to Change permission of fileB (fileB could be fileB*) to change its permission same as the permission of fileA. chmod `ls -l fileA | awk '{pr int "u+", substr($1,2,1), substr($1,3,1), substr($1,4,1), ",g+", substr($1,5,1), substr($1,6,1), substr($1,7,1), ",o+",... (0 Replies)
Discussion started by: gagansharma
0 Replies

2. Shell Programming and Scripting

Changing Permissions

Is it possible to change the permissons for an entire directory in one shot? I'm telneting on to a linux server. ...just a beginner-- --Paul (4 Replies)
Discussion started by: pdavid
4 Replies

3. UNIX for Advanced & Expert Users

Changing file permissions on upload

Hello ! When I connect to a RH FTP server, the files I transfer (from my "windows computer") to this server have the following permissions : -rw------- but I would like those files to have the following permissions : - rw-rw-r-x How can I do that ??? :) Thanks for your help ! G. (6 Replies)
Discussion started by: guix
6 Replies

4. UNIX for Dummies Questions & Answers

changing default file permissions

How can I change the default permissions that are assigned when I create a file? (By default the file has: -rw-r--r-- ..... I'd like it to be -rw-r----- How can I change this default behavior? (8 Replies)
Discussion started by: FredSmith
8 Replies

5. UNIX for Dummies Questions & Answers

Changing file permissions

Is there a way to change a unix user's default file permissions so that when he creates a file, by default permissions are 777??? Thanks! (7 Replies)
Discussion started by: FredSmith
7 Replies

6. UNIX for Dummies Questions & Answers

changing permissions on a 444 file (ie chmod 444)

if I have a file set to permisions 444 (r-- r-- r--) should anyone other than the owner and root be able to change these permissions or delete the file. Apologies if this is a no-brainer but I cant test it myself and someone in our organisation is playin around with files they shouldnt be (1 Reply)
Discussion started by: ajcannon
1 Replies

7. Cybersecurity

changing /cn@0:console file permissions

I'm doing a security sweep of a Sun Sol 5.8 system. The file: /dev/console, which links to /devices/pseudo/cn@0:console, has the following perms: crw--w--w- I would like to get rid of the world write permissions. I can change the file permissions, but as soon as log back in, they are changed... (4 Replies)
Discussion started by: ErnieG
4 Replies

8. Shell Programming and Scripting

HELP changing file permissions

does anyone know how to write a script that will change file permissions. because the Admin blocked me from altering any of my files im only allowed to read and i heard a script like this can bypass it but i dont know how to write it. Display current users. Display user Ids only. Display... (10 Replies)
Discussion started by: live2learn
10 Replies

9. Homework & Coursework Questions

changing permissions of a file whos name was passed to 755

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a shell script that gives a passed file the "755" access permissions. The shell script should: Change... (0 Replies)
Discussion started by: anix007
0 Replies

10. Shell Programming and Scripting

Changing file permissions of a file created by another user

Hi, I have used expdp for datapump. The .dmp file is created by the "oracle" user. my requirement is to make a zipped file of this .dmp file. What i am trying to do is change the permissions of this .dmp file from 0640 to 0644 and then do a gzip and zip it. Is there any way i can change... (3 Replies)
Discussion started by: qwertyu
3 Replies
pam_console_apply(8)					   System Administrator's Manual				      pam_console_apply(8)

NAME
pam_console_apply - set or revoke permissions for users at the system console SYNOPSIS
pam_console_apply [-f <fstab file>] [-c <console.perms file>] [-r] [-t <tty>] [-s] [-d] [<device file> ...] DESCRIPTION
pam_console_apply is a helper executable which sets or resets permissions on device nodes. If /var/run/console.lock exists, pam_console_apply will grant permissions to the user listed therein. If the lock file does not exist, permissions are reset according to defaults set in console.perms files, normally configured to set permissions on devices so that root owns them. When initializing its configuration it first parses the /etc/security/console.perms file and then it searches for files ending with the .perms suffix in the /etc/security/console.perms.d directory. These files are parsed in the lexical order in "C" locale. Permission rules are appended to a global list, console and device class definitions override previous definitions of the same class. ARGUMENTS
-c Load other console.perms file than the default one. -f Load other fstab file than the default one (/etc/fstab). -r Signals pam_console_apply to reset permissions. The default is to set permissions so that the user listed in /var/run/console.lock has access to the devices, and to reset permissions if no such file exists. -t Use <tty> to match console class in console.perms file. The default is tty0. -s Write error messages to the system log instead of stderr. -d Log/display messages useful for debugging. The optional <device file> arguments constrain what files should be affected by pam_console_apply. If they aren't specified permissions are changed on all files specified in the console.perms file. FILES
/var/run/console.lock /etc/security/console.perms /etc/security/console.perms.d/50-default.perms SEE ALSO
pam_console(8) console.perms(5) BUGS
Let's hope not, but if you find any, please report them via the "Bug Track" link at http://bugzilla.redhat.com/bugzilla/ AUTHORS
Nalin Dahyabhai <nalin@redhat.com>, using code shamelessly stolen from parts of pam_console. Support of console.perms.d and other improvements by Tomas Mraz <tmraz@redhat.com>. Red Hat 2005/5/2 pam_console_apply(8)
All times are GMT -4. The time now is 09:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy