Help- writing to dir with no write permissions (script)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help- writing to dir with no write permissions (script)
# 1  
Old 02-03-2013
Help- writing to dir with no write permissions (script)

hello,

I have a question regarding the below script.. I just simply trying to write to a file in directory that does not have write permissions but this is failing .. it still writes to it regardless ..

Many thanks in advance..


Code:
#!/bin/bash
#check if dir exists, if so write to it 



echo " please enter the dir path"
read dir

if [ "$dir" = "" ]
        then
                echo " Please enter a dir name"

elif [ -d $dir -a -w $dir ]

        then
                echo " File hello.out is created"
                echo "wow!!!" > $dir/hello.out
        else
                echo " incorrect"
                exit
fi

# 2  
Old 02-03-2013
Pls post
- long directory listing of $dir's parent dir (e.g. ls -l ..)
- your user name, optionally anonymized (e.g. id)
- xtrace execution log of your script (run with set -vx)

to enable us to help you.
# 3  
Old 02-03-2013
hi RudiC..

please see below .. this the dir that i tried to write too " no_write_perm"


Code:
total 40
8 drwxr-xr-x 29 root root 4096 Feb  3 00:55 ..
8 -rw-r--r--  1 root root    7 Feb  3 01:02 hello.out
8 d---------  2 root root 4096 Feb  3 01:03 test
8 drwxrwxrwt  4 root root 4096 Feb  3 06:09 .
8 d---------  2 root root 4096 Feb  3 06:09 no_write_perm

# 4  
Old 02-03-2013
This is only 1/3 of what I asked you to post. What user are you? Should you be root, no wonder you can write to that dir. Should you not be rot, we need the xtrace log.
# 5  
Old 02-03-2013
Quote:
Originally Posted by RudiC
This is only 1/3 of what I asked you to post. What user are you? Should you be root, no wonder you can write to that dir. Should you not be rot, we need the xtrace log.

i am user root yes.. would that be the reason? sorry-- noob on unix. but why then we have to chmod every script to run it?

also .. the dir has no write permissions ..does root user overwrite this?

i have ran the trace.. shows the following.


Code:
[root@localhost no_write_perm]# sh directorycheck.sh 
sh directorycheck.sh 
+ sh directorycheck.sh
 please enter the dir path
/var/tmp/no_write_perm
 File hello.out is created
echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"
++ echo -ne '\033]0;root@localhost:/var/tmp/no_write_perm'
[root@localhost no_write_perm]#


Last edited by Reb0rn; 02-03-2013 at 10:35 AM..
# 6  
Old 02-03-2013
Being root you can read and write anything. Why you need execute permission on a file, I guess is an additional system security measure. As I'm not sure, let's wait for additional comments...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. UNIX for Advanced & Expert Users

Allow user without dir write permission to execute a script that creates files

In our project we have several unix scripts that trigger different processes. These scripts write logs to a particular folder 'sesslogs', create output data files in a separate directory called 'datafiles' etc. Usually L1 support team re-run these scripts . We donot want L1 support team to have... (14 Replies)
Discussion started by: waavman
14 Replies

3. Shell Programming and Scripting

Have files take on DIR permissions

Hello all; I have a question based on a ticket I have from a user... K...first some background...this client needed a generic user setup to allow them to ftp files; user is called "msifpt"...so here's what they want to do now with this account: 1. Client will use the user id ‘msiftp'... (1 Reply)
Discussion started by: gvolpini
1 Replies

4. Shell Programming and Scripting

Dir permissions

Hi All, I have a script which will be run by another user say user 2 which will create a new dir say dir 4 in my work place and copy certains files from his dir. /t1/t2/t3/dir4 I want to allow the user to create the dir dir4 and copy the files,but bring the control back to my name say user... (2 Replies)
Discussion started by: prasperl
2 Replies

5. Shell Programming and Scripting

help writing rm script excluding specific titled dir

I am attempting to write a housecleaning script that does the following: 1) goes to a specific directory 2) deletes all contents of that directory but a specific directory within it. So my users all keep and use the Shared directory in OSX. Within /Users/Shared there are also standard named... (1 Reply)
Discussion started by: nomados
1 Replies

6. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

7. Shell Programming and Scripting

Shell Script to save/restore files and dir permissions

Hello all: I need found script to save and restore file permissions and owner:group... this is for backup my server... I have one problem in my server and file permissions and owner:group, mess up.. For this reason i need found one way to secure this aspect of the server... Thanks! (1 Reply)
Discussion started by: joangopan
1 Replies

8. Shell Programming and Scripting

i want to write a script to test the folder permissions

Hi All, I want a script to test folder permissions.( to alert me if a folder /abc/xyz does not have 775 permissions). i want to test /abc/xyz is having 775 permissions or not if not it has to alert me. Please help me ASAP Thanks in advance (4 Replies)
Discussion started by: rajesh212512
4 Replies

9. Shell Programming and Scripting

writing files to a dir in round robin order

I have a list of directories. (say a1,a2,a3,a4,a5) I need to get the directory last modified and access the next one to put some files over there (say if a3 is the latest dir modified ie, last time files were put into a3, this time I need to move the files in a4)...and if a5 is the last modified... (6 Replies)
Discussion started by: kanchan_cp
6 Replies

10. UNIX for Dummies Questions & Answers

File and Dir permissions

I would like to configure my SuSE 7.0 workstation more securely. I have attempted for about two weeks to find a guideline on good practices for the file and directory permissions.........but to no avail. Does anyone have a guideline that I could use to help me out. I realize that the distros are... (11 Replies)
Discussion started by: thomas.jones
11 Replies
Login or Register to Ask a Question