You didn't specify which shell you use, so I'm going to assume Bash.
For CPU ustage you can use strace
.
strace -c script.sh
For a simple Hello World script
#!/bin/bash
echo "Hello World"
Output
Hello World
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
17.70 0.000253 14 18 mmap
11.69 0.000167 20 8 openat
9.59 0.000137 9 14 rt_sigaction
7.35 0.000105 13 8 fstat
6.30 0.000090 15 6 mprotect
5.60 0.000080 10 8 close
5.32 0.000076 12 6 read
5.11 0.000073 14 5 stat
4.90 0.000070 70 1 execve
3.50 0.000050 10 5 rt_sigprocmask
2.59 0.000037 37 1 write
2.24 0.000032 10 3 lseek
2.24 0.000032 10 3 brk
2.10 0.000030 10 3 2 ioctl
1.89 0.000027 9 3 1 fcntl
1.40 0.000020 20 1 munmap
1.40 0.000020 20 1 1 access
1.33 0.000019 9 2 getpid
1.26 0.000018 9 2 prlimit64
0.77 0.000011 11 1 dup2
0.70 0.000010 10 1 sysinfo
0.70 0.000010 10 1 getppid
0.70 0.000010 10 1 arch_prctl
0.63 0.000009 9 1 uname
0.63 0.000009 9 1 getuid
0.63 0.000009 9 1 getgid
0.63 0.000009 9 1 getpgrp
0.56 0.000008 8 1 geteuid
0.56 0.000008 8 1 getegid
------ ----------- ----------- --------- --------- ----------------
100.00 0.001429 108 4 total
For memory you can use top
.
While runnig top press o and type e.g. COMMAND=bash
to show entries from the COMMAND
column that are equal to bash
.