Home > centOS, Fedora 12, Solaris, Unix/Linux > centOS – shell me

centOS – shell me

Bash/Perl boycot:

I want c/php as my shell scripting, automation ( where i am bored not to use bash/perl/python , how i did that?)

1. ask the system first

[root@shamun rc2.d]# which bash
/bin/bash
[root@shamun rc2.d]# which perl
/usr/bin/perl
[root@shamun rc2.d]# which php
/usr/bin/php
[root@shamun rc2.d]# which python
/usr/bin/python
[root@shamun rc2.d]# which gcc
/usr/bin/gcc
[root@shamun rc2.d]# which java
/usr/bin/java
[root@shamun rc2.d]#

so, we use like this:

2. BASH script:

#!/bin/bash
echo “Shamun – are you mad? what is this?”
exit 0;

3. PHP Script:

#!/usr/bin/php
<?php
#
# Debug user inputs!
#
echo $argc; print_r ( $argv );
$ret = ‘You didnt input anything type –help’;
$retval = 0;

# Logical statements..!
switch($argv[1]){
case ‘status’:
$ret = system(‘service httpd status’,$retval);
break;

case ‘start’:
$ret = system(‘service httpd start’,$retval);
break;

case ‘stop’:
$ret = system(‘service httpd stop’,$retval);
break;

default:
echo ‘service httpd –help or status, start,stop please!!’;
break;
}

# buffer: flush
echo $ret  . “\r\n”;
# exit script
exit;
?>
~

[root@shamun rc2.d]# service sshd start
2Array
(
[0] => /etc/init.d/sshd
[1] => start
)
Starting httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@shamun rc2.d]#

4. Perl script
#!/usr/bin/perl
echo ‘my perllllll’

5. python/ruby/c/c++/java the sameway………….

Conclusion

argv array argc variable, logical statement apply.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: