1

我如何在每 5000 个段落上更改 wput 的上传目录?我的代码有什么问题?

仅作记录;我需要无限循环,我想 24 小时 365 天运行这个脚本!每 5000 个段落在目录中增加一个数字,例如incoming1-infinite

此致

豪格

#!/bin/bash
for (( ; ; ))
do
  no=1
  while [ $no -le 5000 ]
  do
    perl job.pl false false 1
    cd comp

    for fname in *.jpg;
    do
      mv -i "$fname" ${RANDOM}${RANDOM}.jpg
    done

    for fname in *.jpg;
    do
      mv "$fname" $(echo "$fname" | sha1sum | cut -f1 -d' ').jpg
    done

    if [ $no = '5000' ]
    then
      echo $no
      echo $n
      n=$(( n+1 )) # <-- this one not do what i need :-(

    else
      wput *.jpg ftp://user:pass@ip:port/incoming$n/  # <-- here is the important part 2, i need it to change one directory higher every 5000 passage for example; incoming1 until   infinite       
      rm  -rf *.jpg
      cd ..
    fi

    no=`expr $no + 1`
  done
done
4

3 回答 3

0

只需在无限循环中放置一个执行 5,000 次的 for 循环(它可以为您跟踪目录序列号):

#!/bin/bash
for (( n=0; ; n++ )); do
  for (( no=1; no < 5000; no++ )); do
    perl job.pl false false 1
    ( # Subshell so we don't have to worry about returning
      # to the previous directory.
      cd comp

      # No need to rename each file twice.
      for fname in *.jpg; do
        mv "$fname" $(echo "${RANDOM}${RANDOM}.jpg" | sha1sum | cut -f1 -d' ').jpg
      done

      wput *.jpg ftp://user:pass@ip:port/incoming$n
    )
  done      
done
于 2012-07-31T20:11:37.287 回答
0

只需计算除以 5000 的余数,如果它等于 0(或 1 或任何 < 5000),则执行您需要的操作。

if [ $((no%5000)) = 0 ]
then
...
fi
于 2012-07-31T19:59:09.423 回答
0
cd comp
for ((no=1; ; no++))
do
  n=`expr $no / 5000`

  perl job.pl false false 1

  for fname in *.jpg;

  # ... rest of the script
done
于 2012-07-31T06:54:39.443 回答