[출처 : http://www.perlmonks.org/ ]

Answer: How to run a shell script from a Perl program?
contributed by radiantmatrix

Perl offers three slightly different mechanisms for executing external commands:

  1. system
  2. exec
  3. Backticks or qx//
  1. Using system

    system($command, @arguments); # For example: system( "sh", "script.sh", "--help" ); system("sh script.sh --help");
    System will execute the $command with @arguments and return to your script when finished. You may check $! for certain errors passed to the OS by the external application.

    Read the documentation for system for the nuances of how various invocations are slightly different.

  2. Using exec

    This is very similar to the use of system, but it will terminate your script upon execution. Again, read the documentation for exec for more.

  3. Using backticks or qx//

    my $output = `script.sh --option`; my $output = qx/script.sh --option/;
    The backtick operator and it's equivalent qx// excute the command and options inside the operator and return that commands output to STDOUT when it finishes.

There are also ways to run external applications through creative use of open, but this is advanced use; read the documentation for more.

Answer: How to run a shell script from a Perl program?
contributed by snapdragon

The way to do this is to use a systen call to run your script:

system("script.sh");

However I thought that I'd mention a couple of points to go with this. 

  1. Don't assume that your shell environment variables will be kept - a shell script that works fine on the command line may not work when run from Perl
  2. Be careful with your directories - try to make sure you're executing from the right place. It's often worthwhile to do a chdir to the right directory in Perl before calling your script. i.e.  chdir "/path/to/script/";

Good luck!
Answer: How to run a shell script from a Perl program?
contributed by Plankton

I like to do this sometimes ...

my $shell_out = <<`SHELL`; for fs in `/sbin/fdisk -l | grep -v swap | grep Linux | cut -d ' ' -f1 +` do /sbin/e2label \$fs | grep recovery > /dev/null 2>&1 && echo "Y +ES" && exit 0 done echo "NO" exit 0 SHELL
... to capture the stdout of the shell commands in a scalar var.
Answer: How to run a shell script from a Perl program?
contributed by ruzam

A slightly longer version using the exec method with forked pipes (and an optional timeout value).

# two parameters: # cmd - a command or reference to an array of command + arguments # timeout - number of seconds to wait (0 = forever) # returns: # cmd exit status (-1 if timed out) # cmd results (STDERR and STDOUT merged into an array ref) sub ExecCmd { my $cmd = shift || return(0, []); my $timeout = shift || 0; # opening a pipe creates a forked process my $pid = open(my $pipe, '-|'); return(-1, "Can't fork: $!") unless defined $pid; if ($pid) { # this code is running in the parent process my @result = (); if ($timeout) { my $failed = 1; eval { # set a signal to die if the timeout is reached local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; @result = <$pipe>; alarm 0; $failed = 0; }; return(-1, ['command timeout', @result]) if $failed; } else { @result = <$pipe>; } close($pipe); # return exit status, command output return ($? >> 8), \@result; } # this code is running in the forked child process { # skip warnings in this block no warnings; # redirect STDERR to STDOUT open(STDERR, '>&STDOUT'); # exec transfers control of the process # to the command ref($cmd) eq 'ARRAY' ? exec(@$cmd) : exec($cmd); } # this code will not execute unless exec fails! print "Can't exec @$cmd: $!"; exit 1; }
Answer: How to run a shell script from a Perl program?
contributed by DeadPoet

If you want the PID, STDOUT, and STDERR, use IPC::Open3.

Example:

use IPC::Open3; local (*IN, *OUT, *ERR); my $pid = eval{ open3( \*IN, \*OUT, \*ERR, 'my_command', 'my_command_args' ); }; if ($@) { warn ($@); } ## capture your output, if needed... ## wait on the pid... wait( $pid, 0 );
저작자 표시
신고
Creative Commons License
Posted by rookiejava

아웅... 한두번 하는것도 아닌데...
할때마다 헷갈려서 검색하는것도 귀찮아서 그냥 글로 남겨둬야겠다..


[출처 : http://linuxproblem.org ]

SSH login without password

Your aim

You want to use Linux and OpenSSH to automize your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.

How to do it

First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa): 
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A

Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

a@A:~> ssh b@B mkdir -p .ssh
b@B's password: 

Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password: 

From now on you can log into B as b from A as a without password:

a@A:~> ssh b@B hostname
B

A note from one of our readers: Depending on your version of SSH you might also have to do the following changes:

  • Put the public key in .ssh/authorized_keys2
  • Change the permissions of .ssh to 700
  • Change the permissions of .ssh/authorized_keys2 to 640




저작자 표시
신고
Creative Commons License
Posted by rookiejava

GCC 4 warnings about sentinels

Null-terminate parameter list

Some functions have a variable number of arguments, where the argument list has to be terminated with a NULL value. To solve this warning, null-terminate the list of parameters.

Introduction

When compiling something with GCC 4, it may be possible that you get one of the following warnings:

warning: missing sentinel in function call 
warning: not enough variable arguments to fit a sentinel

This document explains what these warnings mean and how to resolve them.

Sentinels & warnings

A sentinel is a special value which indicates the end of a series of data. In the context of GCC, it is a null pointer which ends a list of parameters to a function.

The function

execl(const char * path, const char * arg, ...)

takes a variable amount of parameters. To know where to stop reading parameters, the last parameter must be a null pointer. When you do not end the list with a null pointer,execl will not stop scanning, which will result in errors. The following code, therefore, is wrong:
#include <unistd.h>

int main() {
	execl("/bin/ls", "ls", "-l");
	return 0;
}

The execl function call is not terminated by a null pointer and GCC will give a warning. The following code is better:

#include <unistd.h>

int main() {
	execl("/bin/ls", "ls", "-l", NULL);
	return 0;
}

As you can see, the execl function is now terminated by a null pointer and it will stop scanning it's arguments after that. However, GCC 4 will still issue a warning: 
warning: missing sentinel in function call 
This is because NULL is not of the right type: it is defined as integer 0 instead of a pointer with the value 0. Doing an explicit cast can make the warning go away:

#include <unistd.h>

int main() {
	execl("/bin/ls", "ls", "-l", (char *)NULL);
	return 0;
}

Using sentinels

One can specify that a function uses a sentinel by declaring it as follows:

char * build_path(const char * str, ...) __attribute__((__sentinel__(0)));

This indicates that the parameter list is ended with the special value 0, which must be a char pointer.

On most systems, there is no difference between 0 and (char *)0. On 64 bit systems, however, the integer 0 is 32 bits and the pointer 0 is 64 bits. The compiler does not know whether it is an integer or a pointer, and defaults for the integer. This will not clear the upper 32 bits and the function will not stop scanning its parameters.


출처 : http://www.linuxonly.nl/docs/2/2_GCC_4_warnings_about_sentinels.html
신고
Creative Commons License

'TIP & TALK > Linux' 카테고리의 다른 글

SSH login without password  (0) 2011.01.20
SQLite Query Syntax  (1) 2010.10.23
missing sentinel in function call  (1) 2010.10.18
Ubuntu NTFS HDD or Partitionnig Problem  (0) 2010.07.16
Ubuntu 파티션 관리  (0) 2010.07.16
Unix socket 사용시 주의사항  (0) 2010.05.04
Posted by rookiejava
1. Go to Applicatoin -> Add/Remove
2. Modify "Show" mode as All avaulable appications
3. search "NTFS"
4. Install "NTFS COnfiguration Tool"
5. Go to System -> Administaration -> NTFS Configuration Tool
6. Enable your internal/external device to support write
신고
Creative Commons License

'TIP & TALK > Linux' 카테고리의 다른 글

SQLite Query Syntax  (1) 2010.10.23
missing sentinel in function call  (1) 2010.10.18
Ubuntu NTFS HDD or Partitionnig Problem  (0) 2010.07.16
Ubuntu 파티션 관리  (0) 2010.07.16
Unix socket 사용시 주의사항  (0) 2010.05.04
Manual Reference Pages - SIGNAL  (0) 2010.04.30
Posted by rookiejava

* 디스크 및 파티션 정보 확인http://rookiejava.tistory.com/owner/entry/edit/60#void

# sudo fdisk -l

* 디스크 UUID 확인

# ls -lh /dev/disk/by-uuid

* 파티션 할당

# sudo fdisk /dev/sdb1

* 파티션 포맷

# sudo mkfs.ext3 /dev/sdb1

* 자동 마운트 설정 (fstab 편집)

# sudo vim /etc/fstab
UUID=XXXXXXXXXXX /backup ext3 defaults,errors=remount-rw 0 1

* mount 정보 갱신

# sudo mount -a


* 파티션 편집기 GUI 설치
# sudo apt-get install gparted
참고 : http://ubuntu.liberotown.com/52


신고
Creative Commons License

'TIP & TALK > Linux' 카테고리의 다른 글

missing sentinel in function call  (1) 2010.10.18
Ubuntu NTFS HDD or Partitionnig Problem  (0) 2010.07.16
Ubuntu 파티션 관리  (0) 2010.07.16
Unix socket 사용시 주의사항  (0) 2010.05.04
Manual Reference Pages - SIGNAL  (0) 2010.04.30
DD (Data Dump) Manual  (0) 2010.04.30
Posted by rookiejava
http://www.squarebox.co.uk/cgi-squarebox/manServer/signal.7
신고
Creative Commons License

'TIP & TALK > Linux' 카테고리의 다른 글

Ubuntu 파티션 관리  (0) 2010.07.16
Unix socket 사용시 주의사항  (0) 2010.05.04
Manual Reference Pages - SIGNAL  (0) 2010.04.30
DD (Data Dump) Manual  (0) 2010.04.30
Linux File System Cache (pdflush)  (0) 2010.04.30
VI 명령어 모음  (0) 2008.06.18
Posted by rookiejava
TAG Linux, signal
http://linux.die.net/man/1/dd

http://www.linuxcertif.com/man/1/dd/ko/


* Example
 : ./path/to/src 에서 1024 byte씩 1000번을 읽어서(block) /path/to/dest에 기록
    (일반적으로 빈 파일 만들때 보통 src를 /dev/zero로 사용한다..)
#dd if=/path/to/src of=/path/to/dest bs=1024 count=1000
신고
Creative Commons License

'TIP & TALK > Linux' 카테고리의 다른 글

Unix socket 사용시 주의사항  (0) 2010.05.04
Manual Reference Pages - SIGNAL  (0) 2010.04.30
DD (Data Dump) Manual  (0) 2010.04.30
Linux File System Cache (pdflush)  (0) 2010.04.30
VI 명령어 모음  (0) 2008.06.18
Shell script ref.  (0) 2007.11.22
Posted by rookiejava
TAG dd, Linux
* File System Cache (pdflus)
 http://blog.naver.com/PostView.nhn?blogId=blackaqua2&logNo=10029350786

* The Linux Page Cache and pdflush
 http://www.westnet.com/~gsmith/content/linux-pdflush.htm
신고
Creative Commons License

'TIP & TALK > Linux' 카테고리의 다른 글

Manual Reference Pages - SIGNAL  (0) 2010.04.30
DD (Data Dump) Manual  (0) 2010.04.30
Linux File System Cache (pdflush)  (0) 2010.04.30
VI 명령어 모음  (0) 2008.06.18
Shell script ref.  (0) 2007.11.22
VI 단축키  (0) 2007.11.22
Posted by rookiejava
Shell script ref site.
-------------------------------

http://wiki.kldp.org/KoreanDoc//Shell_Programming-KLDP

http://www.manpage.co.kr/onlinebook/shell.htm

http://blog.naver.com/adioshun/80017461434

http://blog.naver.com/weekend88?Redirect=Log&logNo=20007886421

http://cafe.naver.com/sama703/16  

http://cafe.naver.com/hackerkim.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=38
신고
Creative Commons License

'TIP & TALK > Linux' 카테고리의 다른 글

Linux File System Cache (pdflush)  (0) 2010.04.30
VI 명령어 모음  (0) 2008.06.18
Shell script ref.  (0) 2007.11.22
VI 단축키  (0) 2007.11.22
LANG  (0) 2007.11.09
RPM 다운로드  (0) 2007.11.09
Posted by rookiejava

VI 단축키

TIP & TALK/Linux 2007.11.22 18:34

원문출처 : Black Space in Smin :: 네이버 블로그

1. vi의 시작

 vi : 편집기 실행
 vi pass.c : 문설르 편집기로 부른다.
 vi + pass : 커스가 마지막으로 간다.

2. vi의 종료

 :wq kim1 : 저장하고 종료(문서이름을 kim1으로 저장)
 :q! : 저장하지 않고 종료
 :wq : 저장하고 종료
 :e! : 편집취소

3. cursor 이동

 G : 문서의 끝으로
 G1 : 1번째줄로 G3 : 번째줄로...
 h,j,k,l : 커서이동 좌하상우 10h, 10j, 10k, 10l 10칸씩이동
 O : 줄의 제일 앞으로 커서이동
 $ : 줄의 제일 마지막으로 커서이동

 Ctrl + f : 다음화면
 Ctrl + b : 이전화면

4. 편집 키
 i : 글자앞부터 글쓰기
 I : 현라인의 첫문자부터 입력
 a : 글자뒤부터 글쓰기
 A : 현라인의 끝문자부터 입력
 o : 세로운 행 삽입 현재커서 뒤
 O : 현재커서 윗줄에 새로운 행 삽입
 x : 한문자 삭제
 10x : 10문자 삭제
 dd: 현재 커서 라인 삭제
 10dd : 10줄 삭제
 dG : 현재 커서 다음부터 끝까지 삭제
 r : 문자치환
 R : 많은 문자 치환 Esc키 필요
 J : 현재라인과 다음 라인을 합하기

5. 반복, 취소

 . : 마지막 명령을 반복
 u : 마지막 실행만 취소
 행분리 : i + Enter
 행결합 : 붙이고 싶은 줄 마지막에 커스를 두고 대문자 J를 누른다.

6. 이동, 복사

 dd , G (커서이동 후) , p --> 이동          p - 버프의 내용을 현재 커스 다음에 put
 yy , G (커서이동 후) , p --> 복사          P - 현재커스 윗쪽에 put함

7. 여러개 파일 open

 $vi pass sma1 book
 :e sam1
 :e book
 :e pass

8. 문자열 치환

 :g/0000/s//7777/g - 현재 문자를 다른 문자로 전체 바꿀때
  (goto, 검색문자열, substitute,치환문자열,global)

 :g/7777/s///g - 특정문자열을 찾아서 삭제
 :g/문자/s//범인/gc  - 바로삭제되지 않고 물어본다.

9. 문자열 찾기

 /  : /뒤에 지정한 문자열을 현재의 위치에서 아래로 찾기
 ?  : ?뒤에 지정한 문자열을 현재의 위체에서 위로 찾기
 n  : 찾기 명령을 한번 실행한 다음 반복해서 같은 방향으로 찾기 계속
 N  : 찾기 명령을 한번 실행한 다음 반복해서 다른 방향으로 찾기 계속
 

10. 기타

 :se nu - set number 라인넘버 보기
 :se nonu - 라인넘버 숨기기

 :!date
 :!who  유닉스의 명령을 vi편집모드에서 내릴수 있다.

 :r sam1 - 문서내용을 삽입 r ! cal 작석한 문서 결합
 :r !finger - 파일을 실행한 내용을 삽입

 :sh - vi를 놔두고 새로운 쉘로 이동

*** vi 환경 구동 파일 ***
$ vi .exrc 환경을 초기설정
set autoindent number showmode tapstop=3
 autoindent : 전라인의 시작부분으로 다음줄 시작
 number : 라인번호 설정
 showmode : 현재 작업하는 것의 간단한 메세지로 표시
 tapstop=3 : Tap키를 누를때 3칸씩 이동

신고
Creative Commons License

'TIP & TALK > Linux' 카테고리의 다른 글

VI 명령어 모음  (0) 2008.06.18
Shell script ref.  (0) 2007.11.22
VI 단축키  (0) 2007.11.22
LANG  (0) 2007.11.09
RPM 다운로드  (0) 2007.11.09
YUM  (0) 2007.11.09
Posted by rookiejava
TAG Linux, vi


티스토리 툴바