阅读背景:

按流程数量排名最高的用户且最活跃

来源:互联网 
if [ -d 
if [ -d $1 ] && [ $#2 -gt 0 ]; then
    find $1 ps aux | awk '{ print $1 }' | sed '1 d' | sort | uniq | while read line true; do  #do forever
                                                                        who $line | sort $2   #show loggerd-in users, sorted alphabetically
                                                                        sleep 10              #wait 10 seconds
                                                                    done                      #carry on 
else
     echo "The parameter is invalid"
    exit 1
fi

Question - Write a shell script which provides every 10 seconds a sorted list (in a file) with the actively logged users aside with the number of processes they own. Each minute the same script will print on the screen in alphabetical order the list of the first 10 users and their group who a) had the most processes in the last 20 seconds, b) had the most active processes from the start of the script. The number of seconds (see 10) and the number of users (see 20) should be provided as parameters in the command line

问题 - 编写一个shell脚本,该脚本每隔10秒就会为主动登录的用户提供一个排序列表(在文件中),并提供他们拥有的进程数。每分钟,相同的脚本将按字母顺序在屏幕上打印前10个用户及其组的列表,a)在过去20秒内拥有最多进程,b)从脚本开始时拥有最活跃的进程。应在命令行中将参数(参见10)和用户数(参见20)作为参数提供

This is what I have now, I dont know if everything will work, but I am struggling with making everything work with the loops.

这就是我现在所拥有的,我不知道一切是否会奏​​效,但我正在努力让一切都与循环一起工作。

1 个解决方案

#1


3  

You would start by researching who, sleep, while, and sort. Then you would come back with a question once you've tried something, however bug-ridden it may be. This is not meant to be criticism, just help in the future for posting more acceptable questions.

你可以从研究谁,睡觉,同时和排序开始。然后,一旦你尝试过某些东西,你就会回答一个问题,不过它可能是错误的。这不是批评,只是帮助将来发布更多可接受的问题。

For what it's worth, your code will probably be a variation on this:

对于它的价值,你的代码可能会对此有所改变:

#!/usr/bin/env bash

while true ; do    # do forever
    who | sort     # show logged-in users, sorted
    sleep 10       # wait a bit
done               # carry on

You'll obviously need to adapt it to your more specific requirements but, since you only asked for a start, there it is.

你显然需要根据你更具体的要求进行调整,但是,既然你只是要求一个开始,那就是它。

Some of your more complex requirements may require tools other than who and probably also require awk for text processing. You'll have to research that bit since it is, after all, your assignment.

您的一些更复杂的要求可能需要除了谁以外的工具,并且可能还需要awk进行文本处理。你必须研究这一点,因为它毕竟是你的任务。


] && [ $#2 -gt 0 ]; then find
if [ -d $1 ] && [ $#2 -gt 0 ]; then
    find $1 ps aux | awk '{ print $1 }' | sed '1 d' | sort | uniq | while read line true; do  #do forever
                                                                        who $line | sort $2   #show loggerd-in users, sorted alphabetically
                                                                        sleep 10              #wait 10 seconds
                                                                    done                      #carry on 
else
     echo "The parameter is invalid"
    exit 1
fi

Question - Write a shell script which provides every 10 seconds a sorted list (in a file) with the actively logged users aside with the number of processes they own. Each minute the same script will print on the screen in alphabetical order the list of the first 10 users and their group who a) had the most processes in the last 20 seconds, b) had the most active processes from the start of the script. The number of seconds (see 10) and the number of users (see 20) should be provided as parameters in the command line

问题 - 编写一个shell脚本,该脚本每隔10秒就会为主动登录的用户提供一个排序列表(在文件中),并提供他们拥有的进程数。每分钟,相同的脚本将按字母顺序在屏幕上打印前10个用户及其组的列表,a)在过去20秒内拥有最多进程,b)从脚本开始时拥有最活跃的进程。应在命令行中将参数(参见10)和用户数(参见20)作为参数提供

This is what I have now, I dont know if everything will work, but I am struggling with making everything work with the loops.

这就是我现在所拥有的,我不知道一切是否会奏​​效,但我正在努力让一切都与循环一起工作。

1 个解决方案

#1


3  

You would start by researching who, sleep, while, and sort. Then you would come back with a question once you've tried something, however bug-ridden it may be. This is not meant to be criticism, just help in the future for posting more acceptable questions.

你可以从研究谁,睡觉,同时和排序开始。然后,一旦你尝试过某些东西,你就会回答一个问题,不过它可能是错误的。这不是批评,只是帮助将来发布更多可接受的问题。

For what it's worth, your code will probably be a variation on this:

对于它的价值,你的代码可能会对此有所改变:

#!/usr/bin/env bash

while true ; do    # do forever
    who | sort     # show logged-in users, sorted
    sleep 10       # wait a bit
done               # carry on

You'll obviously need to adapt it to your more specific requirements but, since you only asked for a start, there it is.

你显然需要根据你更具体的要求进行调整,但是,既然你只是要求一个开始,那就是它。

Some of your more complex requirements may require tools other than who and probably also require awk for text processing. You'll have to research that bit since it is, after all, your assignment.

您的一些更复杂的要求可能需要除了谁以外的工具,并且可能还需要awk进行文本处理。你必须研究这一点,因为它毕竟是你的任务。


ps aux | awk '{ print
if [ -d $1 ] && [ $#2 -gt 0 ]; then
    find $1 ps aux | awk '{ print $1 }' | sed '1 d' | sort | uniq | while read line true; do  #do forever
                                                                        who $line | sort $2   #show loggerd-in users, sorted alphabetically
                                                                        sleep 10              #wait 10 seconds
                                                                    done                      #carry on 
else
     echo "The parameter is invalid"
    exit 1
fi

Question - Write a shell script which provides every 10 seconds a sorted list (in a file) with the actively logged users aside with the number of processes they own. Each minute the same script will print on the screen in alphabetical order the list of the first 10 users and their group who a) had the most processes in the last 20 seconds, b) had the most active processes from the start of the script. The number of seconds (see 10) and the number of users (see 20) should be provided as parameters in the command line

问题 - 编写一个shell脚本,该脚本每隔10秒就会为主动登录的用户提供一个排序列表(在文件中),并提供他们拥有的进程数。每分钟,相同的脚本将按字母顺序在屏幕上打印前10个用户及其组的列表,a)在过去20秒内拥有最多进程,b)从脚本开始时拥有最活跃的进程。应在命令行中将参数(参见10)和用户数(参见20)作为参数提供

This is what I have now, I dont know if everything will work, but I am struggling with making everything work with the loops.

这就是我现在所拥有的,我不知道一切是否会奏​​效,但我正在努力让一切都与循环一起工作。

1 个解决方案

#1


3  

You would start by researching who, sleep, while, and sort. Then you would come back with a question once you've tried something, however bug-ridden it may be. This is not meant to be criticism, just help in the future for posting more acceptable questions.

你可以从研究谁,睡觉,同时和排序开始。然后,一旦你尝试过某些东西,你就会回答一个问题,不过它可能是错误的。这不是批评,只是帮助将来发布更多可接受的问题。

For what it's worth, your code will probably be a variation on this:

对于它的价值,你的代码可能会对此有所改变:

#!/usr/bin/env bash

while true ; do    # do forever
    who | sort     # show logged-in users, sorted
    sleep 10       # wait a bit
done               # carry on

You'll obviously need to adapt it to your more specific requirements but, since you only asked for a start, there it is.

你显然需要根据你更具体的要求进行调整,但是,既然你只是要求一个开始,那就是它。

Some of your more complex requirements may require tools other than who and probably also require awk for text processing. You'll have to research that bit since it is, after all, your assignment.

您的一些更复杂的要求可能需要除了谁以外的工具,并且可能还需要awk进行文本处理。你必须研究这一点,因为它毕竟是你的任务。


}' | sed '1 d' | sort | uniq | while read line true; do #do forever who $line | sort #show loggerd-in users, sorted alphabetically sleep 10 #wait 10 seconds done #carry on else echo "The parameter is invalid" exit 1 fi if [ -d
if [ -d $1 ] && [ $#2 -gt 0 ]; then
    find $1 ps aux | awk '{ print $1 }' | sed '1 d' | sort | uniq | while read line true; do  #do forever
                                                                        who $line | sort $2   #show loggerd-in users, sorted alphabetically
                                                                        sleep 10              #wait 10 seconds
                                                                    done                      #carry on 
else
     echo "The parameter is invalid"
    exit 1
fi

Question - Write a shell script which provides every 10 seconds a sorted list (in a file) with the actively logged users aside with the number of processes they own. Each minute the same script will print on the screen in alphabetical order the list of the first 10 users and their group who a) had the most processes in the last 20 seconds, b) had the most active processes from the start of the script. The number of seconds (see 10) and the number of users (see 20) should be provided as parameters in the command line

问题 - 编写一个shell脚本,该脚本每隔10秒就会为主动登录的用户提供一个排序列表(在文件中),并提供他们拥有的进程数。每分钟,相同的脚本将按字母顺序在屏幕上打印前10个用户及其组的列表,a)在过去20秒内拥有最多进程,b)从脚本开始时拥有最活跃的进程。应在命令行中将参数(参见10)和用户数(参见20)作为参数提供

This is what I have now, I dont know if everything will work, but I am struggling with making everything work with the loops.

这就是我现在所拥有的,我不知道一切是否会奏​​效,但我正在努力让一切都与循环一起工作。

1 个解决方案

#1


3  

You would start by researching who, sleep, while, and sort. Then you would come back with a question once you've tried something, however bug-ridden it may be. This is not meant to be criticism, just help in the future for posting more acceptable questions.

你可以从研究谁,睡觉,同时和排序开始。然后,一旦你尝试过某些东西,你就会回答一个问题,不过它可能是错误的。这不是批评,只是帮助将来发布更多可接受的问题。

For what it's worth, your code will probably be a variation on this:

对于它的价值,你的代码可能会对此有所改变:

#!/usr/bin/env bash

while true ; do    # do forever
    who | sort     # show logged-in users, sorted
    sleep 10       # wait a bit
done               # carry on

You'll obviously need to adapt it to your more specific requirements but, since you only asked for a start, there it is.

你显然需要根据你更具体的要求进行调整,但是,既然你只是要求一个开始,那就是它。

Some of your more complex requirements may require tools other than who and probably also require awk for text processing. You'll have to research that bit since it is, after all, your assignment.

您的一些更复杂的要求可能需要除了谁以外的工具,并且可能还需要awk进行文本处理。你必须研究这一点,因为它毕竟是你的任务。


] && [ $#2 -gt 0 ]; then find
if [ -d $1 ] && [ $#2 -gt 0 ]; then
    find $1 ps aux | awk '{ print $1 }' | sed '1 d' | sort | uniq | while read line true; do  #do forever
                                                                        who $line | sort $2   #show loggerd-in users, sorted alphabetically
                                                                        sleep 10              #wait 10 seconds
                                                                    done                      #carry on 
else
     echo "The parameter is invalid"
    exit 1
fi

Question - Write a shell script which provides every 10 seconds a sorted list (in a file) with the actively logged users aside with the number of processes they own. Each minute the same script will print on the screen in alphabetical order the list of the first 10 users and their group who a) had the most processes in the last 20 seconds, b) had the most active processes from the start of the script. The number of seconds (see 10) and the number of users (see 20) should be provided as parameters in the command line

问题 - 编写一个shell脚本,该脚本每隔10秒就会为主动登录的用户提供一个排序列表(在文件中),并提供他们拥有的进程数。每分钟,相同的脚本将按字母顺序在屏幕上打印前10个用户及其组的列表,a)在过去20秒内拥有最多进程,b)从脚本开始时拥有最活跃的进程。应在命令行中将参数(参见10)和用户数(参见20)作为参数提供

This is what I have now, I dont know if everything will work, but I am struggling with making everything work with the loops.

这就是我现在所拥有的,我不知道一切是否会奏​​效,但我正在努力让一切都与循环一起工作。

1 个解决方案

#1


3  

You would start by researching who, sleep, while, and sort. Then you would come back with a question once you've tried something, however bug-ridden it may be. This is not meant to be criticism, just help in the future for posting more acceptable questions.

你可以从研究谁,睡觉,同时和排序开始。然后,一旦你尝试过某些东西,你就会回答一个问题,不过它可能是错误的。这不是批评,只是帮助将来发布更多可接受的问题。

For what it's worth, your code will probably be a variation on this:

对于它的价值,你的代码可能会对此有所改变:

#!/usr/bin/env bash

while true ; do    # do forever
    who | sort     # show logged-in users, sorted
    sleep 10       # wait a bit
done               # carry on

You'll obviously need to adapt it to your more specific requirements but, since you only asked for a start, there it is.

你显然需要根据你更具体的要求进行调整,但是,既然你只是要求一个开始,那就是它。

Some of your more complex requirements may require tools other than who and probably also require awk for text processing. You'll have to research that bit since it is, after all, your assignment.

您的一些更复杂的要求可能需要除了谁以外的工具,并且可能还需要awk进行文本处理。你必须研究这一点,因为它毕竟是你的任务。





你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: