[SOLVED] CSH Permission Denied When Accessing Local File
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46
Rep:
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
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.
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
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46
Original Poster
Rep:
Quote:
Originally Posted by corp769
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.
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46
Original Poster
Rep:
Quote:
Originally Posted by corp769
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.
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46
Original Poster
Rep:
Quote:
Originally Posted by corp769
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.
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46
Original Poster
Rep:
Quote:
Originally Posted by corp769
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.
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...
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46
Original Poster
Rep:
Quote:
Originally Posted by corp769
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.
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?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.