انجمن‌های فارسی اوبونتو

کمک و پشتیبانی => برنامه‌سازی => نویسنده: یک پسر خلاق در 31 خرداد 1389، 09:21 ب‌ظ

عنوان: چگونه در bash از پایان کار یک دستور مطلع شوم؟؟ )حل شد(
ارسال شده توسط: یک پسر خلاق در 31 خرداد 1389، 09:21 ب‌ظ
سلام
من یه اسکریپت bash نوشته م که خط به خط از فایل میخونه و برای هر خط یه دستور رو اجرا میکنه ولی مشکلی که هست منتظر نمیمونه تا دستور تموم شه و حلقه برای همه ی خط ها اجرا میشه!
چجوری میتونم درستش کنم؟؟ البته من از subshell استفاده نکرده م و در هر اجرای حلقه یه تابع صدا زده میشه!
عنوان: پاسخ به: چگونه در bash از پایان کار یک دستور مطلع شوم؟؟
ارسال شده توسط: fzerorubigd در 01 تیر 1389، 10:59 ق‌ظ
به نظرتون بدون دیدن حتی یه خط از کد شما کسی میتونه کمکتون کنه؟؟
عنوان: پاسخ به: چگونه در bash از پایان کار یک دستور مطلع شوم؟؟
ارسال شده توسط: یک پسر خلاق در 01 تیر 1389، 03:06 ب‌ظ
#!/bin/bash
# Shell script utility to read a file line line.
# Once line is read it can be process in processLine() function
# You can call script as follows, to read myfile.txt:
# ./readline myfile.txt
# Following example will read line from standard input device aka keyboard:
# ./readline
# -----------------------------------------------
# Copyright (c) 2005 nixCraft <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
# User define Function (UDF)
processLine(){
  line="$@" # get all args
  #  just echo them, but you may need to customize it according to your need
  # for example, F1 will store first field of $line, see readline2 script
  # for more examples
  # F1=$(echo $line | awk '{ print $1 }')
 
  link=\"$line\"
echo $link
axel -n 100 -o /media/My Passport/Movies/book/ $line

}
 
### Main script stars here ###
# Store file name
FILE=""
 
# Make sure we get file name as command line argument
# Else read it from standard input device
if [ "$1" == "" ]; then
   FILE="/dev/stdin"
else
   FILE="$1"
   # make sure file exist and readable
   if [ ! -f $FILE ]; then
  echo "$FILE : does not exists"
  exit 1
   elif [ ! -r $FILE ]; then
  echo "$FILE: can not read"
  exit 2
   fi
fi
# read $FILE using the file descriptors
 
# Set loop separator to end of line
BAKIFS=$IFS
IFS=$(echo -en "\n\b")
exec 3<&0
exec 0<"$FILE"
while read -r line
do
# use $line variable to process line in processLine() function
processLine $line
done
exec 0<&3
 
# restore $IFS which was used to determine what the field separators are
IFS=$BAKIFS
exit 0

عنوان: پاسخ به: چگونه در bash از پایان کار یک دستور مطلع شوم؟؟
ارسال شده توسط: fzerorubigd در 02 تیر 1389، 12:51 ب‌ظ
۱- axel یه برنامه دانلوده تا اونجا که من ازش استفاده میکنم و سوئیچ -o برای مشخص کردن "فایل" خروجیه نه پوشه خروجی بنابراین کار شما برای اجرای axel غلطه. از -o به بعدو بردارید.
۲- این اسکریپت یه فایلو میخونه و خط به خط لینکها رو دانلود میکنه،‌یه کم لقمه دور سر چرخوندنه خوب. اینجوری چطوره :
 ### Main script stars here ###
# Store file name
FILE=""
 
# Make sure we get file name as command line argument
# Else read it from standard input device
if [ "$1" == "" ]; then
   FILE="/dev/stdin"
else
   FILE="$1"
   # make sure file exist and readable
   if [ ! -f $FILE ]; then
  echo "$FILE : does not exists"
  exit 1
   elif [ ! -r $FILE ]; then
  echo "$FILE: can not read"
  exit 2
   fi
fi
# read $FILE using the file descriptors
 
cat $FILE | xargs -l1 axel -n 100 -a
exit 0
کد من فقط دو خط آخره. کل کاری که میخوای انجام میده (خط آخرشم زایده :)‌ )
۳-اجرای axel با n 100 نه تنها سرعتو زیاد نمیکنه کندش هم میکنه، به نظر من بیشتر از ۳۰ یا دیگه ۴۰ تیکه کردن فایل برای دانلود یه کم زایده. به جای ۱۰۰ یه عدد منطقی بذار، من ۱۰ رو ترجیح میدم.

الان من اینو که اجرا میکنم مثلا اینجوری :
~/bin/dllinks.sh ~/bin/list
همه لینکهای توی list دانلود میشن.
موفق باشی.
عنوان: پاسخ به: چگونه در bash از پایان کار یک دستور مطلع شوم؟؟
ارسال شده توسط: یک پسر خلاق در 02 تیر 1389، 05:17 ب‌ظ
ممنون! اون خط o- رو پاک کردم a- گذاشتم درست شد! اون پایپ هم که گفتین واقعا کار رو ساده میکنه!