2017-05-14 82 views
-1

我想硬鏈接一個目錄到不同的目錄,但是這個腳本不起作用。由於一些奇怪的原因,它硬鏈接到所有的目錄。所以「tv show dir」被硬連接到'moviesdestpath','tvdestdestpath'和'miscdestpath'bash硬鏈接不起作用

有什麼想法嗎?

#!/bin/bash 
tvdestpath="/rpn-san/downloads/complete/torrents/tvshows-ready/$2" 
moviedestpath="/rpn-san/downloads/complete/torrents/movies-ready/$2" 
miscdestpath="/rpn-san/downloads/complete/torrents/misc-ready/$2" 
torrentid="$1" 
torrentname="$2" 
torrentpath="$3" 
torrentdir="$torrentpath/$torrentname" 

#hardlink to "tvshows-ready" 
cp -al "$torrentdir" "$tvdestpath/" 
sleep 5 
cp -al "$torrentdir" "$moviesdestpath/" 
sleep 5 
cp -al "$torrentdir" "$miscdestpath/" 
+0

請看看:http://www.shellcheck.net/ – Cyrus

+0

我不熟悉「cp」的'-l'選項。你使用的是什麼版本的linux? – Beta

+3

Linux不允許硬鏈接到目錄。 – Barmar

回答

-1

所有的好東西都知道了,我是個白癡。當我不應該時,我會直接複製到所有目錄。

#!/bin/bash 
tvdestpath="/rpn-san/downloads/complete/torrents/tvshows-ready/$2" 
moviedestpath="/rpn-san/downloads/complete/torrents/movies-ready/$2" 
miscdestpath="/rpn-san/downloads/complete/torrents/misc-ready/$2" 
torrentid="$1" 
torrentname="$2" 
torrentpath="$3" 
torrentdir="$torrentpath/$torrentname" 

#hardlink to "tvshows-ready" 
if [ "$torrentpath" == "/rpn-san/downloads/complete/torrents/tvshows" ]; then 
cp -al "$torrentdir" "$tvdestpath/" 
fi 

sleep 5 
#hardlink to "movies-ready" 
if [ "$torrentpath" == "/rpn-san/downloads/complete/torrents/movies" ]; then 
cp -al "$torrentdir" "$moviedestpath/" 
fi 

sleep 5 
#hardlink to "misc-ready" 
if [ "$torrentpath" == "/rpn-san/downloads/complete/torrents/misc" ]; then 
cp -al "$torrentdir" "$miscdestpath/" 
fi