把$HOME/transfer目录下的所有.c文件自动上传到$HOME/processed/下,并在每个.c文件末尾标志为处理过的"Proessed !"

//autotransfer

#!/bin/sh
#FileName:autotransfer
#Function:Auto transfer c file
#Version:V0.1
#Author:Sunrier
#Date:2012-05-16
flag="noexe"
cd $HOME
echo $HOME
if [ -d "transfer" ]
then
        echo "transfer 目录存在 !"
else
        echo "transfer 目录不存在 !"
        echo "创建transfer目录中......"
        mkdir transfer
fi

if [ -d "processed" ]
then
        echo "processed 目录存在 !" 
else
        echo "processed 目录不存在 !"
        echo "创建processed目录中......"
        mkdir processed
fi

cd $HOME/transfer

for pFile in $(ls *.c 2>/dev/null)
do
        flag="exe"
        echo "Start load "${pFile}
        echo "Processed !" >> ${pFile}
        mv $HOME/transfer/${pFile} $HOME/processed/
done

if [ "$flag" = "noexe" ]
then
        echo "本次没有上传文件!"
else
        echo "本次上传文件成功!"
fi



 

 

[Sunrier@localhost bin]$ chmod u+x autotransfer

[Sunrier@localhost bin]$./autotransfer

/home/Sunrier
transfer 目录存在 !
processed 目录存在 !
Start load a.c
Start load b.c
本次上传文件成功!

 

 

2012-05-17改进版本

//autotransfer

#!/bin/sh
#FileName:autotransfer   
#Function:Auto transfer c file   
#Version:V0.2  
#Author:Sunrier   
#Date:2012-05-17   

flag="noexe"

cd $HOME
echo $HOME

if [ "$HOME" != "/home/Sunrier" ]
then
	echo "没有执行权限!"	
	exit 1
fi

if [ -d "transfer" ]
then
	echo "transfer 目录存在!"
else
	echo "transfer 目录不存在!"
	echo "创建transfer目录中......"
	mkdir transfer
fi


if [ -d "processed" ]
then
	echo "processed 目录存在!"
else
	echo "processed 目录不存在!"
	echo "创建pocessed目录中......"
	mkdir processed
fi

cd $HOME/transfer

for pFile in $(ls *.c 2>/dev/null)
do
	flag="exe"
	echo "加载 ${pFile} 中......"
	#echo -e "\n"
	date >> ${pFile}
	echo -e "Processed !\n">> ${pFile}
	mv $HOME/transfer/${pFile} $HOME/processed/
done

if [ "$flag" = "noexe" ]
then
	echo "本次没有上传文件!"
else
	echo "本次上传文件成功!"
fi

exit 0



 

 

Version :V0.3

 

#!/bin/sh
#FileName:autotransfer      
#Function:Auto transfer c file      
#Version:V0.3     
#Author:Sunrier      
#Date:2012-05-18

MAINPATH=$HOME
AUTHPATH="/home/Sunrier"
SOURDIR="transfer"
DESTDIR="processed"
SOURPATH=$MAINPATH/$SOURDIR
DESTPATH=$MAINPATH/$DESTDIR
CURRPATH=$PWD

flag="noexe"

cd $MAINPATH
echo $MAINPATH

if [ "$MAINPATH" != "$AUTHPATH" ]
then
	echo "没有执行权限!"	
	exit 1
fi

if [ -d "$SOURDIR" ]
then
	echo "$SOURDIR 目录存在!"
else
	echo "$SOURDIR 目录不存在!"
	echo "创建$SOURDIR目录中......"
	mkdir $SOURDIR
fi


if [ -d "$DESTDIR" ]
then
	echo "$DESTDIR 目录存在!"
else
	echo "$DESTDIR 目录不存在!"
	echo "创建$DESTDIR目录中......"
	mkdir $DESTDIR
fi

cd $SOURPATH

for pFile in $(ls *.c 2>/dev/null)
do
	flag="exe"
	echo "加载 ${pFile} 中......"
	#echo -e "\n"
	date >> ${pFile}
	echo -e "Processed !\n">> ${pFile}
	mv $SOURPATH/${pFile} $DESTPATH/
done

if [ "$flag" = "noexe" ]
then
	echo "本次没有上传文件!"
else
	echo "本次上传文件成功!"
fi

cd $CURRPATH

exit 0


 

 

 



注:
解决在Windows使用UE编辑代码放到Linux下乱码的问题:
另存为:当前文件名
保存类型:所有文件(*.*)
换行符: UNIX换行符-LF
格式:UTF-8-无BOM



 

 

 

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐