LinuxQuestions.org
Help answer threads with 0 replies.
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 07-28-2003, 10:59 PM   #1
x2000koh
Member
 
Registered: Jul 2002
Location: singapore
Distribution: red had 7.2
Posts: 109

Rep: Reputation: 15
shell script how to execute


Hi all,
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.

#!/bin/bash
date ; who ;

2) Make it excutable
chmod a+x test.sh

3) run the program

test.sh

Question :
when run program (test.sh) it appear the following.

-bash:test.sh: Command not found

Appreciate if anyone can help.
 
Old 07-28-2003, 11:03 PM   #2
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
try ./test.sh
 
Old 07-29-2003, 12:27 AM   #3
x2000koh
Member
 
Registered: Jul 2002
Location: singapore
Distribution: red had 7.2
Posts: 109

Original Poster
Rep: Reputation: 15
login to department folder

Thanks coolman0stress,
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,
x2000koh
 
Old 07-29-2003, 04:51 AM   #4
DIYLinux
Member
 
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 17
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.
 
Old 07-29-2003, 05:32 AM   #5
x2000koh
Member
 
Registered: Jul 2002
Location: singapore
Distribution: red had 7.2
Posts: 109

Original Poster
Rep: Reputation: 15
symlink

DIYLinux
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 ?

Regards,
x2000koh
 
Old 07-29-2003, 07:00 AM   #6
DIYLinux
Member
 
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 17
.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
cat /etc/passwd
# same, with explicit path
/bin/cat /etc/passwd
# now for login.sh
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.
 
Old 07-29-2003, 04:20 PM   #7
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
cannot execute script file from shell shahrahulb Linux - General 4 03-04-2008 07:02 AM
execute shell script in KDE Lotharster Linux - Newbie 1 11-21-2005 06:02 PM
shell script to execute my c executable cranium2004 Programming 2 04-06-2005 05:26 AM
shell script won't execute brandnewbie Linux - Newbie 7 08-10-2004 01:30 PM
how to execute shell script with c code? khucinx Programming 3 05-04-2004 02:54 PM


All times are GMT -5. The time now is 05:05 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration