1

Program A (ReportHandler) calls program B (Specific Report). In order for me to get my "specific report" I need to go through program A, which then calls program B and gets me my report. My problem here is that Program B has a "security" measure that checks for program B to be a child process of program A. (This is because program A makes sure no-one else is running this program B, makes sure it gets run between x and y hour of the day, or other programs that may interfere with the running of program B, etc.)

Program A & B are C based, but I cannot (must not) change them. I checked the code and I cannot pass parameters to program A to run B from console.. SOOO, the only idea I have left, is to try and "trick" the system so that program B shows up as a child of program A so that I can run it from console.

The reason for me to try and automate this, is that I need to dial into a dozen servers each day to get this report... I want to centralize this script so that I can remotely ssh this script to each server and be done with it. would save me an hour of my day. or more.

Check being made

if ( TRUE != child_of_Program_A() )
    {
    epause( win[MAIN], 1,
    _("This Program Must Be Run From Program A"));
    return( FAILURE );
}
STATIC BOOL child_of_Program_A()
{
    FILE *fp;

char statname[32];
pid_t ppid;
char proc_name[32];
char buffer[128];
char *ptr;

ppid = getppid();

while(ppid != 1)
    {
    snprintf(statname, sizeof(statname), "/proc/%d/status", ppid);
    if (NULL == (fp = fopen(statname, "r")))
        {
        return(FALSE);
        }

    proc_name[0] = '\0';
    ppid = -1;

    while (NULL != fgets(buffer, sizeof(buffer), fp))
        {
        if (NULL != (ptr = strtok(buffer, STAT_SEP)))
            {
            if (strcasecmp(ptr, "name") == 0)
                {
                if (NULL != (ptr = strtok(NULL, STAT_SEP)))
                    {

                    if (strcmp(ptr, "Program_A") == 0)
                        {
                        fclose(fp);
                        return(TRUE);
                        }
                    strncpy(proc_name, ptr, sizeof(proc_name));
                    }
                }
            else if (strcasecmp(ptr, "ppid") == 0)
                {
                if (NULL != (ptr = strtok(NULL, STAT_SEP)))
                    {
                    ppid = atoi(ptr);
                    }
                }
            }
        if (ppid != -1 && proc_name[0] != '\0')
            break;
        }

    fclose(fp);
    }

return(FALSE);
4

1 に答える 1

0

私が理解している場合、あなたはこれを必要以上に難しくしています。メニュー迷路のナビゲートを自動化します。あなたが尋ねた非常に珍しいことを本当に試してみたいのでない限り、この代替案を検討してください.

非対話的な方法でプログラム A に入ると、問題が解決します。 scpアカウント内の各サーバーへのシェルスクリプト。シェル スクリプトは、ヒア ドキュメントにすることができます。 stdinキーボードの代わりにスクリプトになります。

プログラム A との正しいインタラクティブ セッションのトランスクリプトがあると仮定すると、次のようになります。

cd /foo
./programA username
password
A
/deviceA/catalog.txt
B
A
13 cows
now  

ヒアドキュメントを使用したスクリプトは次のようになります

#!/bin/ksh
cd /foo
        ./programA username<<EOF
        password
        A
        /deviceA/catalog.txt
        B
        A
        13 cows
        now  
EOF

各リモート サーバーに固有の回答がある場合は、それらを組み込みます。各リモートサーバーに正しいファイルを scp します。

ssh remote_server 'cd /foo && chmod +x ./myscript.sh

これにより、実行権限が設定されます。

ローカル デスクトップで、単純な script.sh を作成します。

ssh remote1  './foo/myscript.sh'
ssh remote2  './foo/myscript.sh'
ssh remote3  './foo/myscript.sh'

この script.sh は、ユーザーの介入なしでレポートを実行するようになりました。また、リモート サーバーに ssh キーを設定していない可能性もあると思います。これにより、上記のスクリプトが必要とするようなパスワードなしのアクセスが可能になります。

http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html

于 2013-03-28T23:46:14.470 に答える