linux 脚本

Last updated on November 22, 2024 pm

🧙 Questions

☄️ Ideas

bash文件等于号之间不能有空格

获取命令行变量

结果变量会变成一个字符串

#!/bin/bash

CURRENT_USERS=$(who)
echo -e "$CURRENT_USERS"

获取命令行结果的每行数据

#!/bin/bash

for metaResult in $(ps -e -o pid,command | grep ispong-admin)
do
    if [ $metaResult == java ]; then 
    	break
	fi
	ispong_PORT=${metaResult}
done

kill -9 $ispong_PORT

if语法

中括号和数据要有空格

#!/bin/bash

if [ 1 -gt 2 ]; then
     echo error
elif [ 3 -lt 2 ]; then
     echo yes
else
     echo exception
fi
获取外部变量
# 获取配置环境
for key in "$@"
do
    ENV=${key#*=}
done

ENV=prod
for key in "$@"
do
    ENV=${key#*=}
done

---
title: Linux 脚本
subtitle: Linux 脚本
tags:
  - linux
categories:
  - Linux
index_img: 'https://img.isxcode.com/index_img/linux/index.png'
mermaid: false
math: false
hide: false
comments: true
date: 2021-07-29 11:41:07
---

## 🧙 Questions

- [](#)

## ☄️ Ideas

```bash
#!/bin/bash

echo "describe 'test'" | ./hbase shell -n > /dev/null 2>&1
status=$?
echo "The status was " $status
if ($status == 0); then
    echo "The command succeeded"
else
    echo "The command may have failed."
fi
return $status

脚本运行

nohup ssh ispong@192.168.16.75 "bash /data/ispong/sh/SQOOP/test.sh" >> /data/ispong/log/SQOOP/test.log 2>&1 &

linux 脚本
https://ispong.isxcode.com/os/linux/linux 脚本/
Author
ispong
Posted on
March 11, 2021
Licensed under