<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>寝る前にラーメン &#187; UNIX</title>
	<atom:link href="http://thleave.com/tag/unix/feed" rel="self" type="application/rss+xml" />
	<link>http://thleave.com</link>
	<description>学生エンジニアのコードに関する忘備録</description>
	<lastBuildDate>Mon, 30 Aug 2010 15:41:01 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>UNIXコマンドをPerl(CGI)で動かそうとする</title>
		<link>http://thleave.com/works/146</link>
		<comments>http://thleave.com/works/146#comments</comments>
		<pubDate>Thu, 12 Nov 2009 18:22:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[お仕事]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://thleave.com/?p=146</guid>
		<description><![CDATA[外部からはSSHが通せないサーバーのスクリプトを動かしたいというのがテーマ。
crontabとかではなくて、任意のタイミングで。

まず、PerlでUNIXコマンドを動かすには方法がいくつかある。

バッククォート(=b [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>外部からはSSHが通せないサーバーのスクリプトを動かしたいというのがテーマ。<br />
crontabとかではなくて、任意のタイミングで。</p>
<p><span id="more-146"></span></p>
<p>まず、PerlでUNIXコマンドを動かすには方法がいくつかある。</p>
<ul>
<li>バッククォート(=backtrick) を使って動かす。<br />
[perl]<br />
print `ls -al`;<br />
[/perl]<br />
出力はコマンドの実行結果。
</li>
<li>system()やexec()などの関数を使う<br />
[perl]<br />
system &#8220;ls -al&#8221;;<br />
[/perl]<br />
出力はコマンドの返値、正否。1とか0とか。詳しくは調べて。
</li>
</ul>
<p>別にどっちを使っても構わないと思う。<br />
<br/></p>
<p>次に問題になるのはログインするユーザー。</p>
<ul>
<li>CGIによるアクセス => nobody</li>
<li>通常のSSHアクセス => rootとか登録されたユーザーとか</li>
</ul>
<p>ファイルを触りたい場合、suするかsudoを使うしかない。</p>
<ol>
<li>suする場合<br />
対話型のコマンドなのでパスワードが必要なユーザーには基本的にはsuできないが、expectを使えばいける。<br />
詳しくは調べてー。インストール必要。
</li>
<li>sudoする場合<br />
サーバー管理者に設定してもらう必要がある。<br />
セキュリティーホールを広げるものなのでー、これは基本的に非推奨だよね。
</li>
</ol>
<p>どちらにせよ、こういうことをするのはセキュリティーを下げてリスクを上げるので良くなさそう。<br />
できそうな感じにはなったけどね。<br />
参考までに。</p>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://thleave.com/works/146/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
