shell script how to execute
I am beginner of shell script. i have created my script as following step.
1) I have created test.sh. The simple content is as follow.
date ; who ;
2) Make it excutable
chmod a+x test.sh
3) run the program
when run program (test.sh) it appear the following.
-bash:test.sh: Command not found
Appreciate if anyone can help.
login to department folder
1) it is working now. I am learning shell script, appreciate your reply.
2) Appreciate if you can help.
The objective : The users can only see his department folder when he login.
In my linux server, I have created 2 departments (acct and mkt department). In acct department, I have (useradd) acctuser1 and acctuser2. In mkt department, I have (useradd) mktuser1 and mktuser2.
In my (/home/AusDepts) is a directory contain all the department folders.(/home/AusDepts/acct) and (/home/AusDepts/mkt).
When acctuser1 login, a soft link (ln -s source target) will be created in his /home/acctuser1 directory link to /home/AusDepts/acct). That's mean when acct user login he can see his accounting department folder. Whereas mktuser login he can see his marketing department folder.
How can I do this ? In my /home/acctuser1/.bash_profile I have added :
ln -s /home/AusDepts/acct acct
But it doesn't link once. First is say the target directory doesn't exit. when I created the target manually, It provide endless link ?
Appreciate if you can advise or provide alternation suggestion to the solution.
Thanks and regards,
Set it up statically, that is make the link only once. Note that only the root can symlink directories, because of security implications.
Perhaps I dont understand what you try to do. Since every user has its own home directory, it should be easy to create a link in his/her home dir to the department dir. If there are (will be) many users, consider creating a script to create. This script should create the /etc/passwd entries (calling adduser or useradd) and create and fill the home directory.
Actually I am working on NIS server and client. That'w why I need to symbolic link.
I manage to write a shell script to evaluate the group ID then do a symbolic link to the user home directory.
Now I need the .bash_profile to call a program login.sh
how can I do that ?
.bash_profile is an ordinary shell script. You can call login.sh like any other executable. Example (provided login.sh is placed in a directory that is in $PATH)
# call bash builtin (there is also a standalone executable, do help set)
echo "The path is $PATH"
# call the cat program
# same, with explicit path
# now for login.sh
Take care of these points:
- The directory in which login.sh is placed should be in the path
- It should be executable by whoevere runs .bash_profile (the owner of the home directory in this case). Do a ls -l, and possibly a chmod.
- Beware of other programs called login.sh, whose directories are also in $PATH. Use the which command to check.
Sorry x2000koh, but i know very little about shell scripting. I just knew the answer to your original question because i encountered it before (it happened because the current directory you worked in wasn't part of the search path, by adding ./ you specify where the file is - you can also directly add your current dir to the path too instead).
Anyway, good luck :)
|All times are GMT -5. The time now is 12:43 PM.|