LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 03-09-2011, 08:49 PM   #1
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Rep: Reputation: 1
Question CSH Permission Denied When Accessing Local File


I've just recently started learning shell scripting and I've been working on a basic csh script, but I've been having a few problems. Here's the script
Code:
#!/bin/csh
echo Enter a file name
$< = FILE                                       ##Name of file
echo enter a size (in kilobytes) to monitor
SIZETOMON = $<                                  ##Size value that's input by user
du -k $FILE = $SIZE                             ##Size of the file that the user wishes to monitor
while (1)
if $SIZE > $SIZETOMON then
echo ALERT: File size is greater than $SIZETOMON
end
And here's the output
Code:
/home/lucer/foo.txt: Permission denied.
Badly placed ()'s.
I'm not really sure what the issue is with the "badly placed ()'s" or why it won't let me access files that I can access with the same shell when it's not in a script. Anyone have any ideas?

Edit:Fixed glaring punctuation error

Last edited by wafflesausage; 03-09-2011 at 08:50 PM.
 
Old 03-09-2011, 09:15 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Try enclosing the echo statements in quotation marks:
Code:
#!/bin/csh
echo "Enter a file name"
$< = FILE
echo "enter a size (in kilobytes) to monitor"
SIZETOMON = $<
du -k $FILE = $SIZE
while (1)
if $SIZE > $SIZETOMON then
echo "ALERT: File size is greater than $SIZETOMON"
end

Last edited by corp769; 03-09-2011 at 09:16 PM.
 
Old 03-09-2011, 09:30 PM   #3
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by corp769 View Post
Try enclosing the echo statements in quotation marks:
Code:
#!/bin/csh
echo "Enter a file name"
$< = FILE
echo "enter a size (in kilobytes) to monitor"
SIZETOMON = $<
du -k $FILE = $SIZE
while (1)
if $SIZE > $SIZETOMON then
echo "ALERT: File size is greater than $SIZETOMON"
end
I just solved the parentheses error by removing the parentheses around "in kilobytes". It seemed to be superficial, and I could probably find a way to esape it, but that's not my actual concern. The permission error is still there.
 
Old 03-09-2011, 10:02 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Are you running the script as your normal user? And is the foo.txt already there? If so, what are the permissions of the file?
 
Old 03-09-2011, 10:10 PM   #5
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by corp769 View Post
Are you running the script as your normal user? And is the foo.txt already there? If so, what are the permissions of the file?
Yes, I tried it before with sudo and it didn't work. I just now I tried it with the permissions of 770 and it worked without root privileges, but now it says
Code:
Enter a file name
/home/lucer/foo.txt
/home/lucer/foo.txt: 1: SDFDFA: not found
enter a size in kilobytes to monitor
89
89: Command not found.
FILE: Undefined variable.
"SDFDFA" is the contents of the file, but I need $FILE to be the input from stdin.
 
Old 03-09-2011, 10:23 PM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
I think you need to have it like so:
Code:
set file = $<
 
Old 03-09-2011, 11:08 PM   #7
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by corp769 View Post
I think you need to have it like so:
Code:
set file = $<
Yes, thanks a lot. Now all I have to do is find a way to chop off the non-numerical data from du and get around the "variable must begin with number" error.
 
Old 03-09-2011, 11:42 PM   #8
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
What do you mean? Show me your code so far.
 
Old 03-10-2011, 12:27 AM   #9
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by corp769 View Post
What do you mean? Show me your code so far.
Code:
#!/bin/csh
echo Enter a file name
set file aFILE = $<                                             ##Name of file
echo enter a size in kilobytes to monitor
set SIZE = $<                                                   ##Size value that's input by user
set SIZETOMON = du -k $aFILE | sed s/$aFILE//g                  ##Size of the file that the user wishes to monitor
while (1)
if $SIZE > $SIZETOMON then
echo ALERT: File size is greater than $SIZETOMON
end
If you want to run it for yourself, you can't specify a full path because of the way I set it set up to sed out the non-numerical characters from the output of du. I'll probably just find a workaround to that myself if it becomes to much of an inconvenience.
 
Old 03-10-2011, 12:36 AM   #10
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Show me the output of "du -k $aFILE" and "du -k $aFILE | sed s/$aFILE//g" if you could so I can see what you are talking about. I would rather see the output on your end. Of course replace aFILE with the actual file and so forth...
 
Old 03-10-2011, 12:22 PM   #11
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by corp769 View Post
Show me the output of "du -k $aFILE" and "du -k $aFILE | sed s/$aFILE//g" if you could so I can see what you are talking about. I would rather see the output on your end. Of course replace aFILE with the actual file and so forth...
Actually, I switched that line so it now reads
Code:
du -k $aFILE | awk '{print $1}'
which prints only the size of the specified file in kilobytes (without the name as it did before). I still get the error that states
Code:
set: Variable name must begin with a letter.
SIZETOMON: Undefined variable.
It was my understanding that in shell scripting that one doesn't have to specify whether a variable is a string, float, integer, etc., but that doesn't seem to be the case here. And just to clarify, aFILE is a variable that is specified by the user which the script "asks for" on line 3.
 
Old 03-10-2011, 12:28 PM   #12
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Code:
set SIZETOMON = `du -k $aFILE | sed s/$aFILE//g`
Just noticed this - Try using backticks. Backticks will execute whatever is inside of them.
 
Old 03-10-2011, 12:30 PM   #13
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
And I have a question about the following:
Code:
set file aFILE = $<
Shouldn't be this?
Code:
set aFILE = $<
 
Old 03-10-2011, 12:39 PM   #14
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by corp769 View Post
Code:
set SIZETOMON = `du -k $aFILE | sed s/$aFILE//g`
Just noticed this - Try using backticks. Backticks will execute whatever is inside of them.
I tried it with the backticks, but it still says
Code:
SIZETOMON: Undefined variable
Without the backticks, it says
Code:
set: Variable must begin with a letter
SIZETOMON: Undefined variable.
Really, what I'm trying to do here is have the SIZETOMON variable have the numerical value of the output of
Code:
du -k $aFILE | awk '{print $1}'
and compare it against SIZE, which is a value input by the user.
 
Old 03-10-2011, 12:42 PM   #15
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Can you do what I asked before about running the "du -k $aFILE | sed s/$aFILE//g" by itself on the command line and substituting the appropriate filename?
 
  


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
/etc/csh.cshrc: Permission denied........................ saqibsh Linux - Software 11 03-29-2010 05:04 AM
csh: permission denied jjguo Linux - Newbie 14 09-17-2008 11:29 PM
Root gets permission denied on rw local filesystem sfc Linux - Software 0 02-17-2006 11:17 AM
Permission Denied for script accessing text file lobo1 Linux - General 2 06-28-2005 12:46 PM
Accessing Win2K Shares-permission denied bdog Linux - Networking 4 01-26-2002 07:26 PM

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

All times are GMT -5. The time now is 06:11 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