Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My chmod is not working. 1

Status
Not open for further replies.

pmking

IS-IT--Management
Mar 1, 2006
59
US
Hello

Below is a snipit of shell script and the process works, but was wondering the chmod part is not working.

if test ! -f /var/logs/collect$month.log
then
touch /var/logs/collect$month.log
chmod 662 /var/logs/collect$month.log
chown userid:usergroup /var/logs/collect$month.log

Also..
I would like to have the script output the each line to my screen. How do I do that, so if I run the scrip, then what do I need to do so the output is on my screen?

Thanks..
 
script output the each line to my screen
set -x
# rest of script here

the chmod part is not working
any error message ? unexpected result ?
Anyway, giving write permission but not read is quite unusual ...

BTW: 662 = -rw-rw--w-

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
So sorry..

I should have put more info.

No error message. The unexpected result is that my /var/logs/collect$month.log file is not chaning permissions, thus not changing owner, which is the next line.

Could it be that I am using write without read, would my current results be that the chmod doesn't work?

Thanks so much and again, sorry for the lack of info in my first post..
 
Have you tried to put set -x before your code to discover what is really executed ?

BTW, where is the fi instruction ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Here is the part of the script in full. The fi is there..

if test ! -f /var/best1_logs/collect$month.log
then
touch /var/logs/collect$month.log
chmod 662 /var/logs/collect$month.log
chown ligv:support /var/logs/collect$month.log
fi

I am having issues getting my set -x to work, this is what I am doing.

-I cd over to the dir where the script resides.
-I then type set -x <and hit enter>
-I now type in my file name that runs my script.

Am I doing the set -x correctly?

 
Here is the correct verion, apparently I have too much info on a directory path from my last post. I will take my time now.. sorry, I just feel rushed from my job:(


if test ! -f /var/logs/collect$month.log
then
touch /var/logs/collect$month.log
chmod 662 /var/logs/collect$month.log
chown ligv:support /var/logs/collect$month.log
fi

But the set -x question still stands...
 
Am I doing the set -x correctly
I don't think so.
Put this instruction in the script:
...
set -x
if test ! -f ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I will try this tomorrow morning, the admins are going to reboot the server now (maintenance time), so I won't be able to try this until tomorrow..

I will keep you posted..
Thanks again PHV....

 
Some hints about debugging
[ol]
[li]As PHV says, use the -x switch. You can do this by
[ol]
[li]Adding the line 'set -x' to your script[/li]
[li]running ksh -x myscript[/li]
[/ol]
[/li]
[li]In a script like yours check the status of the file after every step. Add the line 'ls -l /var/logs/collect$month.log' after each step and you can see what's changing. You can comment them out when the debugging is done[/li]
[li]Stop typos by using variables. You're having to type /var/logs/collect$month.log again and again. If you used logfile=/var/logs/collect$month.log at the top then you would only have to type logfile[/li]
[li]This is style, rather than debugging, but if you indent your if statements it's easier to see where you are[/li]
[/ol]
Putting this all together you have
Code:
set -x
logfile=/var/logs/collect$month.log
if test ! -f $logfile
then
  touch $logfile
  ls -l $logfile
  chmod 662 $logfile
  ls -l $logfile
  chown ligv:support $logfile
  ls -l $logfile
fi

Ceci n'est pas une signature
Columb Healy
 
Thank you for you help and suggestions..

It is working finally, but I am getting a date range issue per another part of the script.. My question to you is how can I add 2 minutes to current server time.

For example:

'date' is a variable in the script, but what I would like to do is add 2 minutes to the date.

Why?

Because the script will be menu driven on the front end, and the 'date' option will allow an operator to schedule a process via this menu script, they just hit enter when prompted for a date, and the date will show 'current' time.

Issue:

Once the operator answers the prompts via this menu driven script, and after he chooses current time via the 'date' perameter by pressing <enter> current date is used. but by the time the other 4 questions are answerd, let say the time is 12:00, and by the time he completes the menu and it is 12:01. An error message states that 'you can't schedule a process in the past'.

Thought of a solution:

Add 2 minutes to the 'date' variable. How do I add 120 seconds to current date?
 
But what if they take three minutes, four?
Why not set the date to 'NOW' so that later on, just before you run the scheduler you have
Code:
if [ "$date" = "NOW" ]
then
  date=$(date)
fi

If you really have to add seconds to the date you need somthing like perl. If you can go to hours then PHV has written this faq80-4800

Ceci n'est pas une signature
Columb Healy
 
Thank you columb,

It will not take any longer than 2 minutes, per our study, the reason is, if the user runs the script at 12:00:56, and by the time the user gets to the end of the menu to run the script, the time is now 12:01:15. I have noticed this error only when the minute hand changes, so I am confident that 2 minutes will sufice.

Any other suggestions beyond the if statement columb suggested?

Thanks a million..

 
What if the operator gets a phone call at the third question out of four, and resumes answering the questions after he/she finishes the phonecall - some 5 minutes further along...

Or don't they have to answer the phone when they are in the middle of something ;-)?


HTH,

p5wizard
 
Have to say I agree with columb and p5wizard. Columb's suggestion cuts out any uncertainty.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top