Shell Call


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Call
# 1  
Old 05-05-2011
Shell Call

Can someone help me figure out how to call a c program from this shell script? I want to echo a #9 option and have it call and execute a c file called dmcc.c.

Code:
#!/bin/sh
# dmc.sh
#clear
# display menu
 
while :
do
echo "1. Display date and time."
echo "2. Display what users are doing."
echo "3. Display network connections."
echo "4. Contact IT Director."
echo "5. Contact System Administrator."
echo "6. Contact Help Desk."
echo "7. Show files in current directory."
echo "8. Show calendar."
echo "x. Exit"
# get input from the user
#
read -p "Enter your choice [ 1 - 8 or "x" to Exit ] " choice
#make decision using case and esac
case $choice in
1)
echo ""
echo "Today is $(date)"
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
;;
2)
echo ""
echo "Current network connections are"
w
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
;;
3)
echo ""
netstat -nat
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
;;
4)
echo ""
dl0101="Doris Long"
dltele="921-555-0101"
echo "IT Director: $dl0101 phone: $dltele"
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
;;
5)
echo ""
mf0202="Mark Filgo"
mftele="972-555-0202"
echo "System Director: $mf0202 phone: $mftele"
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
;;
6)
echo ""
cp0303="Casandra Pitts"
cptele="972-555-5555"
echo "Help Desk Administrator: $cp0303 phone: $cptele"
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
;;
7)
echo ""
echo "List files in PWD"; ls -l;
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
;;
8)
echo ""
cal ;
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
ME=/home/cp0198/
;;
9)
/path/to/c_prog arg1 arg2
x)
echo ""
echo "Bye!"
echo ""
exit 0
;;
*)
echo ""
echo "Error: Invalid option..."
echo ""
read -p "Press [Enter] key to continue..." readEnterKey
;;
esac
echo "My our directory is $HOME."
echo "This is our current path: $PATH."
echo "This is our current server name is $HOSTNAME."
echo "This is our current operating system is $OSTYPE."
echo "The current user is $USER."
done

# 2  
Old 05-05-2011
# 3  
Old 05-05-2011
I put in the full path "/home/(name)/dmcc.c in my code. I can't get it to work. It just keeps looping back. Can someone help
# 4  
Old 05-05-2011
Is dmcc.c a source code file?
Are you simpy trying to print it's contents?

If is is compiled code and executable, are the permissions set as executable?

It is not clear what you are trying to do, open and display or run a program. If it is not compiled it will not run as a program.
# 5  
Old 05-05-2011
When a user presses #9 (which is not in original code) I want it to execute the file dmcc.c, how do I do this?
# 6  
Old 05-05-2011
Again, I need more info...

Is dmcc.c already a compiled program?

Normally c source code (not compiled) has a ".c" extension.
Once compiled, unless specifically told to, it would not have a ".c" extension any longer.

So if you are trying to run the uncompiled c source code... you cannot.
It must be compiled first.

To compile you would first do something like this:
Code:
gcc -o dmcc dmcc.c

# 7  
Old 05-05-2011
ohhh, oops, I guess I was calling the source code....But now when I do it it says no such file or directory, even though I'm pretty sure it is the correct path

---------- Post updated at 02:02 AM ---------- Previous update was at 02:00 AM ----------

I am trying to run the compiled code "dmcc1" thats the name of it, but its telling I have the wrong path, even though its the right path

Last edited by Scott; 05-05-2011 at 04:57 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to call a function in Shell..?

#!/bin/bash FUN_ECHO(){ echo $1 } FUN_ECHO "hi how are you ?" This code will work fine. BUT is it possible to make the following to work ? FUN_ECHO "hi how are you ?" FUN_ECHO(){ echo $1 } I know that the code will be executed line by line. But i have a number of... (5 Replies)
Discussion started by: linuxadmin
5 Replies

2. Shell Programming and Scripting

Call makefile from shell script

I'm writing a VERY simple shell script. I need to call a makefile in a subdirectory. What's the command I need to use? ./dir/make and ./dir/makefile doesn't work. Thanks in advance (1 Reply)
Discussion started by: yamahabob
1 Replies

3. Red Hat

how to call a particular function from one shell another shell script

please help me in this script shell script :1 *********** >cat file1.sh #!/bin/bash echo "this is first file" function var() { a=10 b=11 } function var_1() { c=12 d=13 (2 Replies)
Discussion started by: ponmuthu
2 Replies

4. Shell Programming and Scripting

Call web service from Shell

Hello All, I have to import data from xml file to mysql database multi-time a day. I think it is better to write a tool to help this. So I write a web service in php. I don't know that if we can call a web service via shell script. If it can, I think we can create a cron job to help run it... (2 Replies)
Discussion started by: hapytran
2 Replies

5. Shell Programming and Scripting

how can i call one korn shell from a shell

Hi guys, please help me I have a ksh script (second picture down), in that script I define the function DATECALC. Now I want to use this function KSH in a program shell. How can I call this ksh from my shell program? My shell program is... in the first two lines I tried to call... (1 Reply)
Discussion started by: acevallo
1 Replies

6. UNIX for Advanced & Expert Users

What do you call the > thingy in context of the shell?

I can't for the life of me remember what the name is for ">" My mentor told it to me 20 years ago and I can't remember it now. I know we like to call it re-direct, but there was a name othere than that he used. During a recent training session, someone cut and paste from a file that just happened... (8 Replies)
Discussion started by: theninja
8 Replies

7. Shell Programming and Scripting

Need to call an Executable (.exe) using shell

Hi all , I need to call an executable (.exe) using shell script. Actual need is i need to call that shell script and do an export of some tables is there any way . the executable is datamover Please let me know if there are any option !! (2 Replies)
Discussion started by: raghav1982
2 Replies

8. Shell Programming and Scripting

How to call Java by using shell script

Hi All, I am new to shell script, just wanted you guy to help. How do i call a java program by using shell script, pls give some samle code for it, thank you ver much. (2 Replies)
Discussion started by: aaabbb123123
2 Replies

9. Shell Programming and Scripting

Shell script call from a DB trigger

Has anybody been able to execute a shell script call from a database trigger? If so what are the steps to execute it? Do we have any specific packages in Oracle? Reards, Rahul. (1 Reply)
Discussion started by: rahulrathod
1 Replies

10. UNIX for Advanced & Expert Users

Call Telnet From Within A Shell?

Hi there, I got a big problem. For one of our customers I did a website (php) that connects to another machine "A" (server) to machine "B" via expect. Now he wants that after the the connection with "B" is established, a telnet connection to "C" is opened, and some commands are executed.... (2 Replies)
Discussion started by: Tubbietoeter
2 Replies
Login or Register to Ask a Question