If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Help with permission commands and checking

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-25-11, 22:32
youngyou4 youngyou4 is offline
Registered User
 
Join Date: Apr 2011
Posts: 1
Help with permission commands and checking

Ok so here is my problem and what I have so far.


Rewrite the journal script of Chapter 8 (question 5, page 335) by adding commands to verify that the user has write permission for a file named journal-file in the user's home directory, if such a file exists. The script should take appropriate actions if journal-file exists and the user does not have write permission to the file. Verify that the modified script works.

Here is the script on page 335
$ cat journal

# journal: add journal entries to the file

# $HOME/journal-file



file=$HOME/journal-file

date >> $file

echo -n "Enter name of person or group: "

read name

echo "$name" >> $file

echo >> $file

cat >> $file

echo "----------------------------------------------------" >> $file

echo >> $file

Answer:
# journal: add journal enteries to the file
# ~/journal-file
file=~/journal-file
date >> $file
echo -n "Enter name of person or group: "
read name
echo "$name" >> $file
echo >> $file
cat >> $file
echo "-----------------------------------------" >> $file
echo >> $file




The other problem is
Write a short script that tells you whether the permissions for two files, whose names are given as arguments to the script, are identical. If the permissions for the two files are identical, output the common permission field. Otherwise, output each filename followed by its permission field. (Hint: Try using the cut utility.)

Answer:
#!
# sh comparefiles 1 2
file1_p=$(ls -l $1 | cut -c2-10)
file2_p=$(ls -l $2 | cut -c2-10)

if [ "$file1_p" = "$file2_p" ]; then
echo "match."
echo $file1_p
else
echo "don't match."
echo $1 $file1_p
echo $2 $file2_p
fi


These problems I can't get it to run right... Any help. I think theres something wrong with the else if in the second problem
Reply With Quote
  #2 (permalink)  
Old 04-26-11, 03:25
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
What does "I can't get it to run right" mean?
What error message do you get?
The 2nd script seems OK
Reply With Quote
Reply

Tags
shell script permissions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On