Bash Script Question Maybe easy
Hello All,
I'm trying to rework a script I saw a long time ago(found it and posted it below). It's actually for refreshing student user accounts on OS X, but of course the scripting is the same. I've got it working except for one part. I'm not sure how to make it only run the script if the admin is not logging in. I know I need to use an "if" statement, but how do I check for admin login and then set that as a parameter to not run the script. Here is what I have: Pretty simple. Code:
#!/bin/sh Open to any ideas. Thanks! And it's a very simple adaptation from this. I just don't want it copying whole directories over: Code:
#!/bin/tcsh -f |
Code:
if [ "$1" != "$localAdmin" ] then I do not really understand: Quote:
|
usually, shell script == bash. sometimes dash.
it seems in your post neither the original nor your adaptation are bash. i can see both scripts failing on bash/dash. please clarify. |
Pan64: My goal is to only run the rsync command if the admin user (ddit) doesn't log in. If "ddit" logs in I do not want any changes to the student user so that it can be edited, fixed, saved, etc...
When the student or other user logs in, I would like it to run my rsync command so that every student steps into s fresh environment that was set up before hand. I thought it would work because I stole it from the original script that we used in the past. From my understanding it's checking to see if the local admin is signing in. The actual rsync is working as it should and is tied to the login window as an automatic run command, but can't get the admin user part to work. Does that make sense? At this point my if statement is failing with the following: Code:
./New Student Refresh.sh: line 20: syntax error near unexpected token `fi' ondoh: I can change the #!/bin/sh to #!/bin/bash Does this actually make a difference in the script? I thought that since I used the hashtag it doesn't read that line. Thank you both for your help!!! |
Quote:
|
Quote:
Code:
if CONDITION Alternatively, you could insert a semicolon (i.e., “;”) between the CONDITION and the “then”: Code:
if CONDITION ; then Quote:
Thus, if your script begins with “#!/bin/sh”, then it will be run by the /bin/sh program—i.e., the default command shell on your system. If, on the other hand, it begins with “#!/bin/bash”, then it will be run specifically by the bash shell. Using the default shell should be the more portable option, while bash will generally be more powerful—but if you use any features that only bash supports, then your script will not run on a system on which bash is unavailable. In fact, the “shebang” line can be set to other values as well, such as “#!/usr/bin/perl” (for a Perl script), or “#!/usr/bin/python” (for a Python script), or even “#!/usr/bin/python3” (for a Python script that requires Python 3, and will not work with Python 2). |
All times are GMT -5. The time now is 02:57 AM. |