这可能在某处得到了回答,但我还没有找到。
我有一个简单的 shell 脚本,我想用它来将日志文件移动到我的 Hadoop 集群中。 Logrotate 每天都会调用该脚本。
失败并出现以下错误:“/user/qradar:无法打开 `/user/qradar'(没有这样的文件或目录)”。
#!/bin/bash
#use today's date and time
day=$(date +%Y-%m-%d)
#change to log directory
cd /var/log/qradar
#move and add time date to file name
mv qradar.log qradar$day.log
#load file into variable
#copy file from local to hdfs cluster
if [ -f qradar$day.log ]
then
file=qradar$day.log
hadoop dfs -put /var/log/qradar/&file /user/qradar
else
echo "failed to rename and move the file into the cluster" >> /var/log/messages
fi
目录/user/qradar 确实存在,可以使用 Hadoop 文件命令列出。 我还可以使用 Hadoop 文件命令手动将文件移动到正确的目录中。我可以通过这种方式将文件移动到集群中吗?有没有更好的办法?
欢迎任何想法和评论。 谢谢
最佳答案
&file
是 hadoop dfs -put
行中的拼写错误吗?
如果不是,那么这可能是您的问题,您正在后台运行命令 hadoop dfs -put/var/log/qradar/
(& 符号在后台运行命令),然后是命令 file/user/qradar
,shell 在本地路径上寻找它。
我猜你的意思是以下(美元而不是符号):
hadoop dfs -put /var/log/qradar/$file /user/qradar
关于将文件移动到 hadoop 集群的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12790166/