想法:定一个时间,然后查询需要格式的相关文件,移到一个新的文件夹下面
文件单独检查
进入账号su root
之后,进入到crontab -e
进行添加
#凌晨1点10分 0点30分
10 1 * * * /data/edw_ods/check_st/1move_file.sh
30 0 * * * /data/edw_ods/check_st/0move_file.sh
0move_file.sh
#!/bin/bash
log_file="0update_st_move_file.txt" # 设置日志文件名为 check_st_move_file.txt
echo "开始记录日志..." > $log_file # 创建并初始化日志文件# 20240315
yesterday=$(date -d "1 day ago" +%Y%m%d)
echo $yesterday >> $log_file # 添加当前时间到日志文件source=/data/edw_ods/check/
target=/data/edw_ods/check_st/update_$yesterday
mkdir -p $target#定义字符数组
array=("APPLE" "BANANA" "ORANGE")
#获取数组长度
length=${#array[@]} for ((i = 0; i < length; ++i)); do#打印每个元素echo ${array[i]} >> $log_file # 运行 command1 命令,并将其输出追加到日志文件group_name=${array[i]}find $source -name ${group_name}"_#500_D_"$yesterday"_A_NM_F1.ITF" -exec mv -f {} $target \;find $source -name "YS_"${group_name}"_#500_D_"$yesterday"_A_NM_F1.csv" -exec mv -f {} $target \;
done
1move_file.sh
#!/bin/bash
log_file="1check_st_move_file.txt" # 设置日志文件名为 check_st_move_file.txt
echo "开始记录日志..." > $log_file # 创建并初始化日志文件# 20240315
yesterday=$(date -d "1 day ago" +%Y%m%d)
echo $yesterday >> $log_file # 添加当前时间到日志文件source=/data/edw_ods/check/
target=/data/edw_ods/check_st/$yesterday
mkdir -p $target#定义字符数组
array=("APPLE" "BANANA" "ORANGE")
#获取数组长度
length=${#array[@]} for ((i = 0; i < length; ++i)); do#打印每个元素echo ${array[i]} >> $log_file # 运行 command1 命令,并将其输出追加到日志文件group_name=${array[i]}find $source -name ${group_name}"_#500_D_"$yesterday"_A_NM_F1.ITF" -exec mv -f {} $target \;find $source -name "YS_"${group_name}"_#500_D_"$yesterday"_A_NM_F1.csv" -exec mv -f {} $target \;
done
3succ_file.sh
#!/bin/bash
# 20240315
yesterday=$(date -d "1 day ago" +%Y%m%d)
mv $yesterday/*.ITF ../st
mv $yesterday/*.csv ../st
mv $yesterday _del_$yesterday
密码修改
#!/bin/bashUSERNAME="edw_ods" # 输入你想要修改密码的用户名
PASSWORD="****" # 输入当前的密码
NEW_PASSWORD="****" # 输入新的密码
HOST="127.88.75.122" # 输入主机名或IP地址
PORT=22 # SFTP默认端口号为22echo "Changing password for user $USERNAME on host $HOST..."expect <<EOF
spawn sftp $USERNAME@$HOST:$PORT
set timeout 10expect {"*assword:" { send "$PASSWORD\r"; exp_continue }
}send "passwd\r"
expect {"*New Password*" { send "$NEW_PASSWORD\r"; exp_continue }"*Retype New Password*" { send "$NEW_PASSWORD\r" }
}interact
exit
EOFecho "Password changed successfully."