顯示具有 shellscript 標籤的文章。 顯示所有文章
顯示具有 shellscript 標籤的文章。 顯示所有文章

星期一, 8月 03, 2015

[Shellscript] 批次修改檔名


一行指令修改檔案: D 測試環境Mac OSX已ok

 find . -name '*.jpg' -exec sh -c 'mv "$0" "${0%.jpg}.png"' {} \;


For M$ windows可以參考這個軟體

星期一, 2月 17, 2014

[Shell] 利用 Shell Script 製作選單

如果想要用shellscript寫出程式執行選單可參考以下範例。 拿來寫一些每天常常會打的指令蠻方便的:D
#!/bin/bash
# Bash Menu Script Example

PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
    case $opt in
        "Option 1")
            echo "you chose choice 1"
            ;;
        "Option 2")
            echo "you chose choice 2"
            ;;
        "Option 3")
            echo "you chose choice 3"
            ;;
        "Quit")
            break
            ;;
        *) echo invalid option;;
    esac
done

星期四, 9月 26, 2013

[Shell] 監控JVM使用狀態

為了測試目前記憶體佔用的狀態所寫的shell。


cosa-memory.sh


#!/bin/sh

#author: ken tsai
#date: 2013/7/11

TOMCAT_PID=$(ps aux | grep /bin/java |grep -v grep | grep 'logging' |awk '{print $2}') 

echo "tomcat pid :$TOMCAT_PID"
echo "######################memory monitor##################"
jstat -gcutil -h 10 $TOMCAT_PID 1000

-gcutil Option


Summary of Garbage Collection Statistics
列名描述
S0survivor 0区利用率。
Survivor space 0 utilization as a percentage of
the space’s current capacity.
S1survivor 1区利用率。
Survivor space 1 utilization as a percentage of
the space’s current capacity.
Eeden区利用率。
Eden space utilization as a percentage of
the space’s current capacity.
O年老代空间利用率。
Old space utilization as a percentage of
the space’s current capacity.
P永生代空间利用率。Permanent space utilization as a percentage of
the space’s current capacity.
YGCyoung gc次数。
Number of young generation GC events.
YGCTyoung gc耗时。
Young generation garbage collection time.
FGCfull gc次数。
Number of full GC events.
FGCTfull gc耗时。
Full garbage collection time.
GCTGC总耗时。
Total garbage collection time.
參考資料
http://itzoo.info/?p=256

星期一, 9月 23, 2013

[ShellScript] 用dd指令做硬碟塞爆測試

最近需要透過塞爆硬碟測試一些API,找到了網路上dd指令的介紹。
順便寫了一個簡單的shell script做測試。

of:檔案要存放的位置

//做1G
dd if=/dev/zero of=/tmp/1gb count=1024 bs=1M

//做10G
dd if=/dev/zero of=/tmp/10gb count=10240 bs=1M

//做100G
dd if=/dev/zero of=/tmp/100gb count=102400 bs=1M


//做100G
dd if=/dev/zero of=/tmp/100gb count=100 bs=1G


包裝成shell script使用

目前先都將產生的檔案產生在tmp的目錄下

#!/bin/bash

dummy_path="/tmp/"
count=$1
block_size=$2
block_count=$3

if [ -z "$count" ] || [ -z "$block_size"] || [ -z "$block_count"]
then
echo "Please input paramters for creating dummy file"
else

for ((index=0;index<$count;index++))
do
#echo "file index: $index"
now=$(date +"%m-%d-%Y-%H-%M-%S")
filename="dummyfile_no_${index}_${now}"
echo "create dummy file($index):$filename"
dd if=/dev/zero of="$dummy_path/$filename" count=$block_count bs=$block_size
done
fi

exit 0

$>./dummy_creator 10 1M 1024 # 產生十個1G的檔案

星期三, 3月 28, 2012

[Java] 執行Shell script


想要使用java來執行Shell Script嗎?
透過Process就可以完成了,以下是tail指令的簡單範例,
記得reader要指定編碼,不然中文字會亂碼喔

Process processOnLinux = Runtime.getRuntime().exec("tail -500 " + USR_LOG);
reader = new BufferedInputStream(processOnLinux.getInputStream());
reader = new InputStreamReader(processOnLinux.getInputStream(), "UTF-8");

星期二, 4月 05, 2011

[Asp.Net] 重新註冊IIS .NET Framework

以下程式碼為簡單的範例:請自已修正安裝的.net framework路徑

REM This batch file addresses "Server unavailable" error
@echo off

REM "Changing to the Framework install directory"
cd /d C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

echo "Stopping IIS"
iisreset /stop
echo "----------------------"

echo "Stopping the ASP.NET state service if it is running"
net stop aspnet_state
echo "----------------------"

echo "Re-registering ASP.NET"
aspnet_regiis -i
echo "----------------------"

echo "Restarting IIS"
iisreset /start
echo "----------------------"

其他你感興趣的文章

Related Posts with Thumbnails