LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2007, 11:49 PM   #1
kalyanofb
LQ Newbie
 
Registered: Feb 2007
Posts: 21

Rep: Reputation: 15
Permission problem


Hai,

I wrote a shell script in which i am using lex output file which reads the input file and generates an output file removing comments inside the input file.

While running this script, it gives some permission problem while reading a input file, to avoid this i want to get the permission of the input file and stored in some variable. Then change input file permission to read mode. After execution of lex, i will reset the permission to the input file.

How i will do this?

pls. help me.
 
Old 02-26-2007, 12:51 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
This works for basic permissions (rwx). I don't know if it will choke on special bits (sticky bit, suid, and sgid). If it does, I trust this is enough of a start for you to figure out how to handle them.

Code:
#!/bin/bash

target_file=test_file

original_perms=$( ls -l ${target_file} | cut -c 2-10 )

chmod_mode="u=$(echo ${original_perms} | cut -c 1-3 | sed 's/-//g'),\
g=$(echo ${original_perms} | cut -c 4-6 | sed 's/-//g'),\
o=${echo ${original_perms} | cut -c 7-9 | sed 's/-//g')"

echo "   Original permissions: ${original_perms}"
echo "      chmod mode string: ${chmod_mode}"
echo
echo "Changing permissions to: 777"

chmod 777 ${target_file}

echo "---Displaying file listing---"
ls -l ${target_file}

echo "Changing permissions back to original settings"
chmod ${chmod_mode} ${target_file}

echo "---Displaying file listing---"
ls -l ${target_file}

exit 0
 
  


Reply



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
Samba sharing problem (user permission problem) beikokutn Linux - Software 4 03-11-2008 05:55 AM
permission problem - "You don't have permission to access" radone Linux - General 3 07-24-2006 10:23 AM
Permission Problem Hero Doug Fedora 2 09-12-2005 01:41 AM
Permission problem Commando464 Linux - Newbie 3 07-31-2004 02:53 PM
permission problem trusouthrnplaya Linux - General 2 04-16-2002 12:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:57 AM.

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
Open Source Consulting | Domain Registration