哪里错了呢?
-
- 帖子: 5
- 注册时间: 2009-04-10 22:10
-
- 帖子: 5
- 注册时间: 2009-04-10 22:10
Re: 这个想法如何实现?
这样的功能如何实现? 高手指点一下~
- hellojinjie
- 帖子: 1150
- 注册时间: 2007-09-14 21:03
- 来自: 浙江
-
- 帖子: 1453
- 注册时间: 2008-05-24 8:30
Re: 这个想法如何实现?
代码: 全选
cd ubuntu
for d in *; do
if [ -d "$d" ]; then
h=`date +%H`
while [ $h -ge 7 -a $h -lt 23 ]; do
h=`date +%H`
done
tar cvf "$d.tar" "$d"
fi
done
-
- 帖子: 3
- 注册时间: 2007-09-18 22:19
Re: 哪里错了呢?
貌似很多问题噢。
首先,如果你的目的应该是每小时执行一次。那应该把判断时间的循环放在外面。
另外,建议你的程序每执行一次以后用sleep语句休眠一个小时,而不是轮询CPU。
所以,建议你试试这么写
#!/bin/bash
cd ubuntu
h=`date +%H`
while [ 1 -eq 1 ]; do
if [ $h -ge 7 -a $h -lt 23 ]; then
#do nothing
else
for d in *; do
if [ -d "$d" ]; then
tar cvf "$d.tar" "$d"
fi
done
fi
sleep 3600
h=`date +%H`
done
首先,如果你的目的应该是每小时执行一次。那应该把判断时间的循环放在外面。
另外,建议你的程序每执行一次以后用sleep语句休眠一个小时,而不是轮询CPU。
所以,建议你试试这么写
#!/bin/bash
cd ubuntu
h=`date +%H`
while [ 1 -eq 1 ]; do
if [ $h -ge 7 -a $h -lt 23 ]; then
#do nothing
else
for d in *; do
if [ -d "$d" ]; then
tar cvf "$d.tar" "$d"
fi
done
fi
sleep 3600
h=`date +%H`
done
-
- 帖子: 5
- 注册时间: 2009-04-10 22:10
Re: 哪里错了呢?
程序出现错误
./a: line 7: 在未预料的“else”附近出现语法错误
./a: line 7: `else'
也就是对ubutnu目录中的目录单独打包,到7点就暂停,23点开始直到打完
./a: line 7: 在未预料的“else”附近出现语法错误
./a: line 7: `else'
也就是对ubutnu目录中的目录单独打包,到7点就暂停,23点开始直到打完
-
- 帖子: 3
- 注册时间: 2007-09-18 22:19
Re: 哪里错了呢?
这样行不?
#!/bin/bash
cd ubuntu
h=`date +%H`
while [ 1 -eq 1 ]; do
if [ $h -lt 7 -o $h -ge 23 ]; then
for d in *; do
if [ -d "$d" ]; then
tar cvf "$d.tar" "$d"
fi
done
fi
sleep 3600
h=`date +%H`
done
#!/bin/bash
cd ubuntu
h=`date +%H`
while [ 1 -eq 1 ]; do
if [ $h -lt 7 -o $h -ge 23 ]; then
for d in *; do
if [ -d "$d" ]; then
tar cvf "$d.tar" "$d"
fi
done
fi
sleep 3600
h=`date +%H`
done
-
- 帖子: 34
- 注册时间: 2008-09-21 1:01
Re: 哪里错了呢?
niceshyl 写了:这样行不?
#!/bin/bash
cd ubuntu
h=`date +%H`
while [ 1 -eq 1 ]; do
if [ $h -lt 7 -o $h -ge 23 ]; then
for d in *; do
if [ -d "$d" ]; then
tar cvf "$d.tar" "$d"
fi
done
fi
sleep 3600
h=`date +%H`
done
-
- 帖子: 5
- 注册时间: 2009-04-10 22:10
Re: 哪里错了呢?
测试了一下,不能运行。
还有就是,这个程序需要添加什么参数吗?
还有就是,这个程序需要添加什么参数吗?
-
- 帖子: 34
- 注册时间: 2008-09-21 1:01
Re: 哪里错了呢?
这个程序可以运行阿,不用加任何参数的,把它放在跟ubuntu文件夹同一层的目录下运行就可以了。shyl 写了:这样行不?
#!/bin/bash
cd ubuntu
h=`date +%H`
while [ 1 -eq 1 ]; do
if [ $h -lt 7 -o $h -ge 23 ]; then
for d in *; do
if [ -d "$d" ]; then
tar cvf "$d.tar" "$d"
fi
done
fi
sleep 3600
h=`date +%H`
done
- hellojinjie
- 帖子: 1150
- 注册时间: 2007-09-14 21:03
- 来自: 浙江