<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Linux Forum &mdash; Как из кода сделать скрипт?]]></title>
		<link>https://linuxforum.ru/viewtopic.php?id=6290</link>
		<atom:link href="https://linuxforum.ru/extern.php?action=feed&amp;tid=6290&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «Как из кода сделать скрипт?».]]></description>
		<lastBuildDate>Sat, 04 Sep 2010 13:21:40 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Как из кода сделать скрипт?]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=87565#p87565</link>
			<description><![CDATA[<div class="quotebox"><cite>drBatty пишет:</cite><blockquote><p>если кто-то бьётся головой об стену, это не говорит о безопасности этого занятия. К тому-же, этот кто-то в каске</p></blockquote></div><div class="quotebox"><cite>Termo пишет:</cite><blockquote><p>почему я не могу запустить от рута программу если я этого желаю?<br />просто я не совсем понял о чем речь пошла...</p></blockquote></div><p>Обсуждение продолжено в <a href="http://linuxforum.ru/viewtopic.php?id=6318">другой теме</a>&nbsp; smile <br />Эти два последних сообщения вынужден удалить...</p>]]></description>
			<author><![CDATA[null@example.com (Teocally)]]></author>
			<pubDate>Sat, 04 Sep 2010 13:21:40 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=87565#p87565</guid>
		</item>
		<item>
			<title><![CDATA[Re: Как из кода сделать скрипт?]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=87248#p87248</link>
			<description><![CDATA[<div class="quotebox"><cite>Termo пишет:</cite><blockquote><p>или sudo sh script.sh?</p></blockquote></div><p>если вы хотите приключений на свою ... то именно так.<br /><strong>но лучше НЕ надо</strong><br />таким образом запускается вредоносное ПО, только-что скаченное из сети.<br /></p><div class="quotebox"><cite>Writer пишет:</cite><blockquote><p>2. сделать исполняемым chmod a+x script.sh</p></blockquote></div><p>желательно chmod 744 script.sh<br />и ещё - если вы не понимаете точно, как это работает - лучше сделать отдельного юзера, там сделать скрипт, и там-же его запускать. Во всяком случае, этот скрипт не сможет прибить ваши нужные данные. (в большинстве дистрибутивов).</p><p><strong>sudo в убунте == права суперпользователя == убитая система и ваши данные.</strong></p>]]></description>
			<author><![CDATA[null@example.com (drBatty)]]></author>
			<pubDate>Fri, 03 Sep 2010 15:54:29 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=87248#p87248</guid>
		</item>
		<item>
			<title><![CDATA[Re: Как из кода сделать скрипт?]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=87178#p87178</link>
			<description><![CDATA[<p>замечания по скрипту<br />1. лучше запускать от root<br />2. работает по скорости средне, a la defraggler.exe<br />3. большие файлы обрабатывает медленно и печально, дефрагментирует слабо<br />как пример, раздел /home - было 22,12%, стало 17,71%<br />раздел /usr было 2,23%, стало 0,81%</p><p>в общем, раз в год можно сделать.</p>]]></description>
			<author><![CDATA[null@example.com (Termo)]]></author>
			<pubDate>Fri, 03 Sep 2010 12:57:59 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=87178#p87178</guid>
		</item>
		<item>
			<title><![CDATA[Re: Как из кода сделать скрипт?]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=87140#p87140</link>
			<description><![CDATA[<div class="quotebox"><cite>Termo пишет:</cite><blockquote><p>1. сохранить как script.sh<br />2. сделать исполняемым chmod a+x script.sh<br />3. войти в директорию и запустить? cd ../.. script.sh<br />или sudo sh script.sh?</p></blockquote></div><p>да.</p>]]></description>
			<author><![CDATA[null@example.com (Writer)]]></author>
			<pubDate>Fri, 03 Sep 2010 12:11:31 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=87140#p87140</guid>
		</item>
		<item>
			<title><![CDATA[Re: Как из кода сделать скрипт?]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=87138#p87138</link>
			<description><![CDATA[<p>краткость - сестра таланта?<br />понимаю...</p>]]></description>
			<author><![CDATA[null@example.com (Termo)]]></author>
			<pubDate>Fri, 03 Sep 2010 12:11:11 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=87138#p87138</guid>
		</item>
		<item>
			<title><![CDATA[Re: Как из кода сделать скрипт?]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=87125#p87125</link>
			<description><![CDATA[<p>./name</p>]]></description>
			<author><![CDATA[null@example.com (zerg)]]></author>
			<pubDate>Fri, 03 Sep 2010 11:37:37 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=87125#p87125</guid>
		</item>
		<item>
			<title><![CDATA[Как из кода сделать скрипт?]]></title>
			<link>https://linuxforum.ru/viewtopic.php?pid=87113#p87113</link>
			<description><![CDATA[<p>вот исходный код<br /></p><div class="codebox"><pre><code>#!/bin/bash
# defrag v0.08 by Con Kolivas &lt;kernel@kolivas.org
# Braindead fs-agnostic defrag to rewrite files in order largest to smallest
# Run this in the directory you want all the files and subdirectories to be
# reordered. It will only affect one partition. It works best when run twice.
# Are you really crazy enough to be using this? It might blow your data
# into tiny little useless chunks.


trap &#039;abort&#039; 1 2 15

renice 19 $$ &gt; /dev/null

abort()
{
    echo -e &quot;\nAborting&quot;
    rm -f tmpfile dirlist
    exit 1
}

fail()
{
    echo -e &quot;\nFailed&quot;
    abort
}

declare -i filesize=0
declare -i numfiles=0

#The maximum size of a file we can easily cache in ram
declare -i maxsize=$((`awk &#039;/MemTotal/ {print $2}&#039; /proc/meminfo`*1024))
(( maxsize-= `awk &#039;/Mapped/ {print $2}&#039; /proc/meminfo` ))
(( maxsize/= 2))

if [[ -a tmpfile || -a dirlist  ]] ; then
    echo dirlist or tmpfile exists
    exit 1
fi

# Sort in the following order:
# 1) Depth of directory
# 2) Size of directory descending
# 3) Filesize descending
# I made this crap up. It&#039;s completely unvalidated.

echo &quot;Creating list of files...&quot;

#stupid script to find max directory depth
find -xdev -type d -printf &quot;%d\n&quot; | sort -n | uniq &gt; dirlist

#sort directories in descending size order
cat dirlist | while read d;
do
    find -xdev -type d -mindepth $d -maxdepth $d -printf &quot;\&quot;%p\&quot;\n&quot; | \
        xargs du -bS --max-depth=0 | \
        sort -k 1,1nr -k 2 |\
        cut -f2 &gt;&gt; tmpfile
    if (( $? )) ; then
        fail
    fi

done

rm -f dirlist

#sort files in descending size order
cat tmpfile | while read d;
do
    find &quot;$d&quot; -xdev -type f -maxdepth 1 -printf &quot;%s\t%p\n&quot; | \
        sort -k 1,1nr | \
        cut -f2 &gt;&gt; dirlist
    if (( $? )) ; then
        fail
    fi
done

rm -f tmpfile

numfiles=`wc -l dirlist | awk &#039;{print $1}&#039;`

echo -e &quot;$numfiles files will be reordered\n&quot;

#copy to temp file, check the file hasn&#039;t changed and then overwrite original
cat dirlist | while read i;
do
    (( --numfiles ))
    if [[ ! -f $i ]]; then
        continue
    fi

    #We could be this paranoid but it would slow it down 1000 times
    #if [[ `lsof -f -- &quot;$i&quot;` ]]; then
    #    echo -e &quot;\n File $i open! Skipping&quot;
    #    continue
    #fi

    filesize=`find &quot;$i&quot; -printf &quot;%s&quot;`
    # read the file first to cache it in ram if possible
    if (( filesize &lt; maxsize ))
    then
        echo -e &quot;\r $numfiles files left                                                            \c&quot;
        cat &quot;$i&quot; &gt; /dev/null
    else
        echo -e &quot;\r $numfiles files left - Reordering large file sized $filesize ...                \c&quot;
    fi

    datestamp=`find &quot;$i&quot; -printf &quot;%s&quot;`
    cp -a -f &quot;$i&quot; tmpfile
    if (( $? )) ; then
        fail
    fi
    # check the file hasn&#039;t been altered since we copied it
    if [[ `find &quot;$i&quot; -printf &quot;%s&quot;` != $datestamp ]] ; then
        continue
    fi

    mv -f tmpfile &quot;$i&quot;
    if (( $? )) ; then
        fail
    fi
done

echo -e &quot;\nSucceeded&quot;

rm -f dirlist</code></pre></div><p>как из него сделать исполняемый скрипт?</p><p>1. сохранить как script.sh<br />2. сделать исполняемым chmod a+x script.sh<br />3. войти в директорию и запустить? cd ../.. script.sh<br />или sudo sh script.sh?</p><p>или я что-то упустил?<br />*просто я уже давненько ничего не запускал* <img src="https://linuxforum.ru/img/smilies/ab.gif" alt="ab" /></p>]]></description>
			<author><![CDATA[null@example.com (Termo)]]></author>
			<pubDate>Fri, 03 Sep 2010 11:18:56 +0000</pubDate>
			<guid>https://linuxforum.ru/viewtopic.php?pid=87113#p87113</guid>
		</item>
	</channel>
</rss>
