Showing posts with label Execute Shell Script. Show all posts
Showing posts with label Execute Shell Script. Show all posts

Saturday, February 11, 2017

VBScript Lunch Program Using Shell Execute

VBScript is a scripting language to manage computer developed by Microsoft. Below is a code snippet to open an external program using Shell Application.

Dim objShell

Program_Name = "Notepad.exe"
Arguments = "" 'Optional
Directory = "" 'Optional
Operation = "open" 'open,edit,find,print,properties
Show_Option = 1 

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute Program_Name, Arguments, Directory, Operation, Show_Option

Set objShell = Nothing

'0 = Open the application with a hidden window.
'1 = Open the application with a normal window. If the window is minimized or maximized, the system restores it to its original size and position.
'2 = Open the application with a minimized window.
'3 = Open the application with a maximized window.
'4 = Open the application with its window at its most recent size and position. The active window remains active.
'5 = Open the application with its window at its current size and position.
'7 = Open the application with a minimized window. The active window remains active.
'10 = Open the application with its window in the default state specified by the application.

Sunday, August 25, 2013

Call and store response from a url using bash script

#!/bin/bash

## generate random string of length 18

function randpass
{
        echo `</dev/urandom tr -dc A-Za-z0-9 | head -c18`
}


## get current time stamp

timestamp=$(date  +%s);
sessionId="$(randpass).$(randpass).$timestamp";
privateKey='test';
 

## get substring of sessionId from 0 to 5 characters.
sessionIdPart=${sessionId:0:5};
systemKeyPart=${privateKey:0:4};


## reverse string and store in a variable

word="$(echo "$sessionIdPart" | rev)$(echo "$systemKeyPart" | rev)";
word="$word$sessionId$privateKey";
 

## make a string md5
hash=`echo -n "$word" | md5sum | awk '{print $1}'`;
hash=${hash:0:10};
breakRest="securedSessionKey=$sessionId&securedHash=$hash";
 

saveFile=$(date +"%Y-%m-%d %T")
## saveFile would be '2013-08-25 19:23:28'

## calling a url using 'curl' and store response to some file.
curl -s -L -o "$saveFile.html" "http://domain.com/getStudent?$breakRest" &
## "&" sign at the end means run curl in background.

exit 1;

Tuesday, December 4, 2012

Execute shell commands in PHP

/**
Method to execute a command in the terminal
Uses :

1. system
2. passthru
3. exec
4. shell_exec

 */
function terminal($command)
{
    //system
    if (function_exists('system')) {
        ob_start();
        system($command, $return_var);
        $output = ob_get_contents();
        ob_end_clean();
    } //passthru
    else if (function_exists('passthru')) {
        ob_start();
        passthru($command, $return_var);
        $output = ob_get_contents();
        ob_end_clean();
    } //exec
    else if (function_exists('exec')) {
        exec($command, $output, $return_var);
        $output = implode("\n", $output);
    } //shell_exec
    else if (function_exists('shell_exec')) {
        $output = shell_exec($command);
    } else {
        $output = 'Command execution not possible on this system';
        $return_var = 1;
    }

    return array('output' => $output, 'status' => $return_var);
}

Use as this way:
$o = terminal('ls');
print_r($o);

http://www.binarytides.com/execute-shell-commands-php/