[SOLVED] disable/enable C-Shell Script (CSH) for certain user
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
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.
disable/enable C-Shell Script (CSH) for certain user
Dear all,
is there any way to enable/disable csh script only for one/certain user(s).
I ask this because one of my user can no longer use a csh script while others can. Even a simple helloworld
Code:
#!/bin/csh
echo "helloworld"
returns nothing. No error, no result, nothing.
while other users having no problem with csh script.
It happens after I did a WHM upgrade, and when I realized...
Check ~user/.tcshrc and ~user/.cshrc files. The tcsh shell reads those (the first one that it finds) every time it starts, for example when executing a script. Most likely the user has put something in there that makes tcsh abort before doing anything worthwhile.
I've search my machine, and can't find any .tcshrc or .cshrc
If only one user is affected, then it should be in that user's home directory. That's what ~user/ refers to. That is the most likely culprit, although if they do not exist, the problem could lie in other shell startup files for that user, like .profile or .login .
If all the shell startup files are in order, then it could be a SELINUX problem; perhaps you have changed the security context for that user?
If only one user is affected, then it should be in that user's home directory. That's what ~user/ refers to. That is the most likely culprit, although if they do not exist, the problem could lie in other shell startup files for that user, like .profile or .login .
That two files are not exist in any user.....
the admin user used to have a .history file that only contains one command:
Code:
exit
I've already remove that code, but still no luck....
Quote:
Originally Posted by Nominal Animal
If all the shell startup files are in order, then it could be a SELINUX problem; perhaps you have changed the security context for that user?
The only thing that I can tell from SELINUX is that it's status is SELINUX=disabled with SELINUXTYPE=targeted
The command will list the files the csh opens (using a successfulopen syscall) when it starts up. It includes libraries ( .so files), not all of them are shell scripts.
I believe the problem lies in one of the script files listed by the above command for the problematic user, and that the list must be different for the problematic user than for a user who has no issues with csh. If the lists differ, perhaps you could show the offending file here?
(Alternatively, one of the common script files could have a test using the [FONT=Monospace] id [FONT]command or the USER environment variable, which only matches the problematic users, and causes the shell to exit prematurely. I think this is highly unlikely though, because non-user-specific shell startup files are owned by root. Such changes would have to have been made by somebody with root access, in other words.)
file /etc/profile.d/locallib.csh contains this code:
Code:
#cPanel Added local::lib -- BEGIN
setenv LOCALLIBUSER $USER
if ( -e /usr/bin/whoami ) then
setenv LOCALLIBUSER `whoami`
endif
if ( "$LOCALLIBUSER" != "root" ) then
eval $(perl -Mlocal::lib)
endif
#cPanel Added local::lib -- END
and when I execute it, I got this errors:
Code:
# /etc/profile.d/locallib.csh
/etc/profile.d/locallib.csh: line 2: setenv: command not found
/etc/profile.d/locallib.csh: line 10: syntax error: unexpected end of file
@yoachan: Those differences between users are quite surprising. Normally, I'd expect the only differences to be in per-user files. Perhaps the actual shell run for the problematic user is different. Could you check what the commands
# /etc/profile.d/locallib.csh
/etc/profile.d/locallib.csh: line 2: setenv: command not found
/etc/profile.d/locallib.csh: line 10: syntax error: unexpected end of file
does not really make sense; it looks like the .csh file was run by a sh shell. Did you remember to source it (as they are intended to be), i.e. using
@yoachan: Those differences between users are quite surprising. Normally, I'd expect the only differences to be in per-user files. Perhaps the actual shell run for the problematic user is different. Could you check what the commands
In some way I think it's due to the script didn't state #!/bin/csh in it's first line.....
No; you see, they are not really standalone scripts, but just snippets that are run by the same shell. They mostly set up environment variables and stuff like that.
You should think of source as include: it does not execute the argument as a separate thing, but includes it into the current shell, just as if you had typed or included those files in the script itself. All shells support this.
This is the file that causes the problem. Note that the working shells did not read this file.
Although all your users use the same shell, it is in a different mode. A shell can be a login shell, an interactive shell, a combination of the two, or a non-login non-interactive shell. Really, the only difference between these modes are the files the shell sources at startup. Different shells have different modes, but that's not important right now: all you need to understand is that depending on how and why csh or tcsh is run, it sources different files when it starts, and that the abovementioned file has a problem which causes the shell to fail before doing anything. (The man pages do list the files for each shell, but it is very convoluted. I don't recommend worrying about those unless you really have to; they confuse me too. I sometimes just end up doing the strace instead of working thorough the documentation!)
"Illegal variable name" is actually quite helpful error message. It usually occurs when you accidentally insert a control character, or replace an ASCII letter with an accented one -- say, an Unicode glyph that looks almost the same. In other words, /etc/profile.d/locallib.csh almost certainly has a typo in it. The other possibility is a problem in the Perl bit.
To check if the file has invalid characters in it, could you run and show the output for
Code:
hexdump -C /etc/profile.d/locallib.csh
This will display every byte in that file in hexadecimal, with ASCII representation on the right. It is the same for all users, so it is enough to run it for one user only.
That script also sources some code Perl should output. It seems strange to me, but what would I know.. Anyway, if you could run (for a working and a nonworking user) and show the output of
Code:
perl -Mlocal::lib | hexdump -C
we could make sure the error does not lie there.
If there is something you'd like to keep private in the above output, you can obfuscate the output by replacing each character with X; just remember to replace the hexadecimal number on the left side with XX too.
Quote:
Originally Posted by yoachan
but here's the fun part. For the problematic user, I tried a simple script echoing "Hello World":
That command starts a new csh shell in a mode where the profile files are not sourced. Because in that mode csh does not source /etc/profile.d/locallib.csh which causes the failure, your command succeeds!
Anyway, if you could run (for a working and a nonworking user) and show the output of
Code:
perl -Mlocal::lib | hexdump -C
we could make sure the error does not lie there.
perl -Mlocal::lib | hexdump -C returns nothing for either users....
Is it possible if somehow I just make csh to skip those included files? Because the worked users seems to have less file include lines compared with problematic users...?
perl -Mlocal::lib | hexdump -C returns nothing for either users....
Well, that's the problem, then.
I did a little more digging, and found the reason. It is pure cPanel stupidity. The /etc/profile.d/locallib.csh file breaks for every single tcsh user. You, like many others, really use tcsh (instead of a "native" csh). It is very surprising, and I'm a bit miffed I didn't think to check earlier.
Fortunately, the fix is trivial. Replace $(perl -Mlocal::lib) with `perl -Mlocal::lib` ; after the replacement your /etc/profile.d/locallib.csh should contain
Code:
#cPanel Added local::lib -- BEGIN
setenv LOCALLIBUSER $USER
if ( -e /usr/bin/whoami ) then
setenv LOCALLIBUSER `whoami`
endif
if ( "$LOCALLIBUSER" != "root" ) then
eval `perl -Mlocal::lib`
endif
#cPanel Added local::lib -- END
Or, you can just remove the entire file. It's only useful for cPanel developers who use Perl. (I think the cPanel bug reports recommend just deleting the file. Any cPanel Perl developers can always add something similar to their own profile files, if they really need it, after all.)
I hope this solves your problem. (If it does, please remember to prepend [SOLVED] to the thread title.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.